需要在 build.gradle 中写入条件,如果满足它应该从特定的工件下载依赖项
Need to write condition in build.gradle , if that satisfies it should download dependencies from specific artifactory
我正在设置新的 gradle 项目,并想在 build.gradle 中编写一个条件,以便在该条件满足时从某个工件下载依赖项。
我正在使用 project.hasProperty("property")
,我的存储库块如下。
mavenCentral()
if(project.hasProperty("isRelease")){
println("Inside gradle")
maven { url 'release url' }
} else {
println("Inside snapshot")
maven { url 'snapshot url' }
}
mavenLocal()
}```
就这样传过去:
-PisRelease=Release
我试过这段代码:
repositories {
if(project.isRelease == "Release"){
println("I'm in")
}
mavenLocal()
}
并且工作正常。
UPDATE 解决方案在关于直接检查版本 属性 的评论中谈到。我已将版本放在 build.gradle 中,但也适用于 gradle.properties 中的版本
build.gradle
version="1.0.0-SNAPSHOT"
repositories {
if (isRelease()){
maven { url 'release url' }
} else {
maven { url 'snapshot url' }
}
mavenLocal()
}
def isRelease() {
if(project.version.contains("SNAPSHOT")){
println("Is a SNAPSHOT")
} else if(!project.version.contains("SNAPSHOT") || project.version.contains("RC")){
println("Is Release")
}
}
您当然可以根据需要修改isRelease
逻辑。只是一个例子。
希望对您有所帮助
我正在设置新的 gradle 项目,并想在 build.gradle 中编写一个条件,以便在该条件满足时从某个工件下载依赖项。
我正在使用 project.hasProperty("property")
,我的存储库块如下。
mavenCentral()
if(project.hasProperty("isRelease")){
println("Inside gradle")
maven { url 'release url' }
} else {
println("Inside snapshot")
maven { url 'snapshot url' }
}
mavenLocal()
}```
就这样传过去:
-PisRelease=Release
我试过这段代码:
repositories {
if(project.isRelease == "Release"){
println("I'm in")
}
mavenLocal()
}
并且工作正常。
UPDATE 解决方案在关于直接检查版本 属性 的评论中谈到。我已将版本放在 build.gradle 中,但也适用于 gradle.properties 中的版本
build.gradle
version="1.0.0-SNAPSHOT"
repositories {
if (isRelease()){
maven { url 'release url' }
} else {
maven { url 'snapshot url' }
}
mavenLocal()
}
def isRelease() {
if(project.version.contains("SNAPSHOT")){
println("Is a SNAPSHOT")
} else if(!project.version.contains("SNAPSHOT") || project.version.contains("RC")){
println("Is Release")
}
}
您当然可以根据需要修改isRelease
逻辑。只是一个例子。
希望对您有所帮助