Home > Mobile >  Gradle Groovy property logical results appear wrong?
Gradle Groovy property logical results appear wrong?

Time:04-10

I have this debug code in root/build.gradle:

task copyJenkinsIdea(type: Copy) {
    onlyIf {
        project.hasProperty("isJenkins")
    }
    doLast {
        println "Do Jenkins-specific setup" 
        println "${project.hasProperty("isJenkins")} && ${isJenkins} = ${(project.hasProperty("isJenkins") && isJenkins)}"
        println "${project.hasProperty("isJenkins")} && ${project.isJenkins} = ${(project.hasProperty("isJenkins") && project.isJenkins)}"
        println "true && false = ${(true && false)}"
    }
        from ".idea/Jenkins"
        into ".idea"
    
}

I run it with this command:

./gradlew --console=verbose -PisJenkins=false assembleDebug

Task dependency in root/app/build.gradle

preBuild.dependsOn(":copyJenkinsIdea")

And it gives me this output:

> Configure project :app
[snip]

> Task :copyJenkinsIdea
Do Jenkins-specific setup
true && false = true
true && false = true
true && false = false

The property is not present in the gradle.properties file.

I've got to be missing something, because this is impossible.

CodePudding user response:

Turns out, Groovy can't know that the property being passed in is a boolean. It's doing

class java.lang.Boolean && class java.lang.String
true && "false"

Which is, in fact, true.

  • Related