settings.gradle

include ':projectA',':projectB'

了projectA /的build.gradle

task task1()  {
    doFirst {
        println 'setting project.ext.testProperty1'
        project(':projectB').ext.testProperty1 = 'MyProperty'
    }
}

task task2 (dependsOn: ['task1', ':projectB:task3']) {
    doLast {
        println "Executed project B Task3 from projectA task2"
    }
}

项目B /的build.gradle

task task3() {
    doLast {
        println "task3 from projectB"
        println project(':projectB').ext.testProperty1
        if(project(':projectB').ext.hasProperty("testProperty1")) {
            ext.prop1  = project.property("testProperty1")
            println "+++++++++If : Clause++++++++++++++++++++++++++++++++"
        } else {
            println "+++++++++Else  :Clause++++++++++++++++++++++++++++++++"
        }
    }
}

现在,当我调用gradle task2时,我得到的输出总是

$ ../gradlew task2
:projectA:task1
setting project.ext.testProperty1
:projectB:task3
task3 from projectB
MyProperty
+++++++++Else  :Clause++++++++++++++++++++++++++++++++
:projectA:task2
Executed project B Task3 from projectA task2

它从不进入“ If”子句,我想念的是什么,它甚至似乎在ProjectB中获得了ext.property testProperty1,但是hasProperties似乎无法正确评估它。

===============>>#1 票数:1

如果您从代码中删除“ ext”

if(project(':projectB').ext.hasProperty("testProperty1")) 

改为将其更改为

if(project(':projectB').hasProperty("testProperty1")) 

然后转到if子句,我不知道为什么在读取时使用ext会导致在写入时使用ext时引起问题。

  ask by user3555410 translate from so

未解决问题?本站智能推荐: