Java Jenkins在Gradle中使用条件依赖关系的最佳方法
信息:在Windows7上使用Gradle2.14构建JAVA多项目 在我的机器上构建时,我希望使用我机器上的库/子项目。 Jenkins在构建项目时,应使用my repo中的库/子项目 所以我做了一个“JenkinsTask”,它只存在于我的IF语句中。这几乎已经按照我想要的方式工作了。下面是我的根项目gradle脚本中的代码:Java Jenkins在Gradle中使用条件依赖关系的最佳方法,java,jenkins,gradle,dependencies,Java,Jenkins,Gradle,Dependencies,信息:在Windows7上使用Gradle2.14构建JAVA多项目 在我的机器上构建时,我希望使用我机器上的库/子项目。 Jenkins在构建项目时,应使用my repo中的库/子项目 所以我做了一个“JenkinsTask”,它只存在于我的IF语句中。这几乎已经按照我想要的方式工作了。下面是我的根项目gradle脚本中的代码: task JenkinsTask() { //doing nothing } def ProjectB_Version //defined on command l
task JenkinsTask() {
//doing nothing
}
def ProjectB_Version //defined on command line
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(JenkinsTask)) {
println "Archiva dependency"
dependencies {
compile group: 'Lib_ProjectB', name: 'ProjectB', version: ProjectB_Version
}
}
else {
println "Filesystem dependency"
dependencies {
compile fileTree(dir: 'ProjectB\\build\\libs', includes: ['*.jar'])
}
}
}
compileJava.dependsOn ":ProjectB:build"
在我的机器上,我只运行了gradlebuild-PProjectB_Version=0.5
我在Jenkins上运行gradle:buildJenkins任务-x:ProjectB:build-PProjectB_Version=0.5
现在的问题是,是否有一种“渐进式”的方法可以做到这一点?因此,我不需要if/else语句,甚至可以放弃“-x”paramater Jenkins命令行。尤其是“詹金斯任务”感觉像是一个黑客
提前谢谢。我不确定这是否被认为是一种渐进的方式,但我认为无论是谁构建项目,在哪里构建项目,都应该以同样的方式声明依赖关系。 相反,我认为你应该:
if (project.hasProperty('jenkins')) {
repositories {
maven {
url "${jenkinsRepoUrl}"
}
}
} else {
repositories {
mavenLocal()
mavenCentral()
}
}
dependencies {
compile (
['commons-lang:commons-lang:2.4'],
["Lib_ProjectB:ProjectB:${ProjectB_Version}"],
}
}
并以gradle clean build-PProjectB_Version=0.5
本地和gradle clean build-Pjenkins-PProjectB_Version=0.5-PjenkinsRepoUrl的形式运行构建=https://nexuscn.my-company.com/content/repositories/main
关于詹金斯
注意:我会在project gradle.properties中声明
ProjectB_Version
属性,因为您的代码可能依赖于实际版本的API。我不确定它是否被视为一种gradle方式,但我认为无论是谁构建项目,在何处,您都应该以相同的方式声明依赖关系。
相反,我认为你应该:
if (project.hasProperty('jenkins')) {
repositories {
maven {
url "${jenkinsRepoUrl}"
}
}
} else {
repositories {
mavenLocal()
mavenCentral()
}
}
dependencies {
compile (
['commons-lang:commons-lang:2.4'],
["Lib_ProjectB:ProjectB:${ProjectB_Version}"],
}
}
并以gradle clean build-PProjectB_Version=0.5
本地和gradle clean build-Pjenkins-PProjectB_Version=0.5-PjenkinsRepoUrl的形式运行构建=https://nexuscn.my-company.com/content/repositories/main
关于詹金斯
注意:我将在project gradle.properties中声明ProjectB_Version
属性,因为您的代码可能依赖于实际版本的API