Java gradle中的条件依赖
我正在使用gradle进行多项目构建。 我有一个在命令行中注入属性的条件的要求 情景1:Java gradle中的条件依赖,java,gradle,Java,Gradle,我正在使用gradle进行多项目构建。 我有一个在命令行中注入属性的条件的要求 情景1: dependencies { if( ! project.hasProperty("withsources")){ compile 'com.xx.yy:x-u:1.0.2' }else{ println " with sources" compile p
dependencies {
if( ! project.hasProperty("withsources")){
compile 'com.xx.yy:x-u:1.0.2'
}else{
println " with sources"
compile project (':x-u')
}
}
1.每当我执行渐变运行-Pwithsources
it is printing "withsources"
it is not printing "withsources"
二,。但是对于gradle run
it is printing "withsources"
it is not printing "withsources"
情景2:
dependencies {
if( project.hasProperty("withsources")){
compile 'com.xx.yy:x-u:1.0.2'
}else{
println " with sources"
compile project (':x-u')
}
}
1.每当我执行渐变运行-Pwithsources
it is printing "withsources"
it is not printing "withsources"
二,。但是对于gradle run
it is printing "withsources"
it is not printing "withsources"
我不知道它总是转到其他循环。任何人都可以在这里提供帮助。如果没有看到完整的构建,我真的无法说出您的问题所在。gradle但是您的一般方法是正确的 下面是一个对我有用的小例子:
plugins {
id "java"
}
repositories {
jcenter()
}
dependencies {
if (project.hasProperty("gson")) {
implementation "com.google.gson:gson:2.8.5"
} else {
implementation "org.fasterxml.jackson.core:jackson-core:2.9.0"
}
}
无财产:
$ gradle dependencies --configuration implementation
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
implementation - Implementation only dependencies for source set 'main'. (n)
\--- org.fasterxml.jackson.core:jackson-core:2.9.0 (n)
(n) - Not resolved (configuration is not meant to be resolved)
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
$ gradle -Pgson dependencies --configuration implementation
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
implementation - Implementation only dependencies for source set 'main'. (n)
\--- com.google.gson:gson:2.8.5 (n)
(n) - Not resolved (configuration is not meant to be resolved)
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
关于财产:
$ gradle dependencies --configuration implementation
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
implementation - Implementation only dependencies for source set 'main'. (n)
\--- org.fasterxml.jackson.core:jackson-core:2.9.0 (n)
(n) - Not resolved (configuration is not meant to be resolved)
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
$ gradle -Pgson dependencies --configuration implementation
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
implementation - Implementation only dependencies for source set 'main'. (n)
\--- com.google.gson:gson:2.8.5 (n)
(n) - Not resolved (configuration is not meant to be resolved)
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
您是否可能在其他地方定义了资源?例如?请忽略这是我的错误,没有检查gradle.properties听起来像你想要的。由于复合构建是在groovy中声明的,所以这可能是有条件的