$. syntax within project scope

Not sure if this is a potential bug, my misunderstanding:

Take the simple example from the variant docs

model {
    tasks {
        buildAllExecutables(Task) {
            dependsOn $.binaries.findAll { it.buildable }
        }
    }
}

This works just fine. Now embed the same code within a multi-project, single build script situation i.e.

project(’:bob’) { // <-- this bit’s new

model {
    tasks {
        buildAllExecutables(Task) {
            dependsOn $.binaries.findAll { it.buildable }
        }
    }
}

} // <-- this bit’s new

and you get the error:

build file ‘test.gradle’: 12: Invalid variable name. Must include a letter but only found: $. At [12:23] @ line 12, column 23.
dependsOn $.binaries.findAll { it.buildable }

It appears you can’t use the $. syntax, once you’re within the project scope.

You can pull the content out into a separate file, then apply from, but …

Is it my misunderstanding of $., is there some alternative/appropriate syntax or is there an issue?

Anyone any ideas ?

This is a bug. I filled GRADLE-3570.

Thanks for confirming Paul - good to know.

Are there any workarounds?

Yup - as suggested in the original post, and “apply from: external-script.gradle” within the project scope.

Then put the offending logic in the external script. e.g.

build.gradle

project(':bob') {
    apply from: "external-logic.gradle"
}

external-logic.gradle

model {
    tasks {
             buildAllExecutables(Task) {
                 dependsOn $.binaries.findAll { it.buildable }
            }
     }
}
1 Like