我有一个下面的POM文件。我想使用xmlSlurper groovy代码来读取POM文件的特定内容,谁能告诉我如何编写代码来通过groovy xmlSlurper读取特定内容。我想读取下面POM文件中作用域为运行时的那些的groupid工件id、分类器和类型。
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ss.engine</groupId>
<artifactId>nti</artifactId>
<version>4.0.0.110</version>
<description>Configuration Management Gradle Plugin</description>
<dependencies>
<dependency>
<groupId>com.ss.engine</groupId>
<artifactId>License</artifactId>
<version>4.0.0.5000</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.as.engine</groupId>
<artifactId>commoncore</artifactId>
<version>4.0.0.100</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.as.engine</groupId>
<artifactId>ncdes</artifactId>
<version>4.0.0.97</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.as.enginee</groupId>
<artifactId>kgfhs</artifactId>
<version>4.0.0.137</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.operasolutions</groupId>
<artifactId>Risk</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamonapi</groupId>
<artifactId>jamon</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.as.engine</groupId>
<artifactId>les</artifactId>
<version>0.0.3</version>
<type>zip</type>
<classifier>linux</classifier>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.28</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv-dozer</artifactId>
<version>2.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
下面是我用来读取POM文件内容并从ArtiFactory下载其作用域为运行时的依赖项的脚本。
apply plugin: 'java'
// ------ Tell the script to get dependencies from artifactory ------
repositories {
maven {
url "http://abc.de.fg:80/artifactory/fes-release-local"
}
}
buildscript {
repositories {
maven {
url "http://abc.de.fg:80/artifactory/libs-snapshot"
}
}
// ------ Tell the script to get dependencies from artifactory ------
dependencies {
classpath ([ "cop.trn.cm:cmugin:1.2.147" ])
}
}
apply plugin: 'com.uven.eplugin'
/**
* The folloing -D parameters are required to run this task
* - deployLayer = one of acceptance, latest, production, test
*/
//------------------------------------------------------------------------------------------
// Read the properties file and take the value as per the environment.
//
//------------------------------------------------------------------------------------------
if(!System.properties.deployLayer) throw new Exception ("deployLayer must be set")
def thePropFile = file("config/${System.properties.deployLayer}.properties")
if(!thePropFile.exists()) throw new Exception("Cannot load the specified environment properties from ${thePropFile}")
println "Deploying ${System.properties.jobName}.${System.properties.buildNumber} to ${System.properties.deployLayer}"
// load the deploy properties from the file
def deployProperties = new Properties()
thePropFile.withInputStream {
stream -> deployProperties.load(stream)
}
// set them in the build environment
project.ext {
deployProps = deployProperties
deployRoot = deployProperties["${System.properties.jobName}.deployroot"]
deploydir = deployProperties["${System.properties.jobName}.deploydir"]
deployFolder = deployProperties["${System.properties.jobName}.foldername"]
deployPostInstallSteps = deployProperties["${System.properties.jobName}.postInstallSteps"]
}
task deleteGraphicsAssets(type: Delete, dependsOn: deploy) {
def dirName = "${deployRoot}"
delete dirName
doLast {
file(dirName).mkdirs()
}
}
task downloaddependecies(dependsOn: deleteGraphicsAssets) << {
def pomFile = file("${buildDir}/artifacts").listFiles().find { it.name.endsWith 'pom' }
def pomXml = new XmlSlurper().parse(pomFile.absolutePath)
def pomDependencies = pomXml.dependencies.dependency
Configuration configuration = project.configurations.detachedConfiguration()
configuration.transitive = false
pomDependencies.each { dependency ->
if(dependency.scope == 'runtime') {
def dependencySpec = dependencies.create("${dependency.groupId}:${dependency.artifactId}:${dependency.version}:${dependency.classifier}@${dependency.type}")
println "Found Runtime Dependency: ${dependencySpec}"
configuration.dependencies.add(dependencySpec)
}
}
println "RESOLVED THE FOLLOWING"
configuration.resolvedConfiguration.firstLevelModuleDependencies.each { println it }
copy {
from configuration
into ( "${buildDir}/artifacts" )
}
}
task copyartifactZip << {
copy {
from "${deployRoot}"
into "${deploydir}/"
}
}
task copyLicenseZip << {
copy {
from "${deployRoot}"
into "${deploydir}/${deployFolder}"
}
}
task myCustomTask(dependsOn: downloaddependecies) << {
copy {
from 'deploymentfiles'
into "${deployRoot}"
}
}
task unzipArtifact(dependsOn: myCustomTask) << {
def theZip = file("${buildDir}/artifacts").listFiles().find { it.name.endsWith('.zip') }
println "Unzipping ${theZip} the artifact to: ${deployRoot}"
ant.unzip(src: theZip, dest: "${deployRoot}", overwrite: true)
}
task setPerms(type:Exec, dependsOn: unzipArtifact) {
workingDir "${deployRoot}"
executable "bash"
args "-c", "chmod -fR 755 *"
}
def dirName = "${deploydir}/${deployFolder}"
task zipDeployment(type: GradleBuild, dependsOn: setPerms) { GradleBuild gBuild ->
def env = System.getenv()
def jobName=env['jobName']
if (jobName.equals("LicenseGenerator")) {
delete dirName
file(dirName).mkdirs()
gBuild.tasks = ['copyLicenseZip']
} else {
gBuild.tasks = ['copyartifactZip']
}
}
task deployAll(dependsOn: zipDeployment){}
目前,如果我试图在Gradle中做类似的事情,排除将被忽略,并且下载所有六个工件。 我使用的是Gradle版本1.8。
大约一个小时后,我无法通过下载URL属性检索文件内容。
问题内容: 我的Unix机器上有文件test.json,其数据如下 现在,我正在编写 REST jersey客户端 以读取test.json并显示如下输出 如何阅读test.json并显示其内容? 问题答案: 对于: 对于: 您的数据将在对象内部
本文向大家介绍JS通过ajax动态读取xml文件内容的方法,包括了JS通过ajax动态读取xml文件内容的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了JS通过ajax动态读取xml文件内容的方法。分享给大家供大家参考。具体分析如下: 下面的JS代码读取note.xml文件,并填充显示相关字段 HTML文件代码如下 xml文件内容如下 希望本文所述对大家的javascript程序设计
逐行读取文本文件的内容,每次一行(比 FileReadLine 执行的更好)。 Loop, Read, InputFile [, OutputFile] 参数 Read 此参数必须为单词 READ. InputFile 需要在循环中读取内容的文本文件的名称, 如果未指定绝对路径则假定在 %A_WorkingDir% 中. 支持 Windows 和 Unix 格式; 即文件的行结束符可以是回车和换行
问题内容: 问题。 Gradle依赖管理使得: 没有简便的方法来检查依赖项更新的可用性(仅使用某些第三方插件,如ben-manes / gradle-versions-plugin)并下载更新以替换旧版本; 从远程存储库下载依赖项工件,然后将其存储在gradle缓存中,并在后续构建中重用;但是项目的成功编译必须不依赖于与Internet的连接,远程存储库的可用性以及这些存储库中特定版本的依赖项。