$. syntax within project scope

issue-acknowledged
gradle-3570

(David Falkinder) #1

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 ?


Native syntax error on testSuites definition
(Paul Merlin) #2

This is a bug. I filled GRADLE-3570.


(David Falkinder) #3

Thanks for confirming Paul - good to know.


(Alex Perry) #4

Are there any workarounds?


(David Falkinder) #5

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 }
            }
     }
}