Within a custom gradle plugin the project.version seems to always be unspecified. Why and how to retrieve the project.version within a custom plugin (class)?
For Example:
apply plugin: 'java'
apply plugin: MyPlugin
version = "1.0.0"
println "In build file: $project.version"
class MyPlugin implements Plugin<Project> {
public void apply(Project project) {
project.task('myTask') {
println "In plugin: $project.version"
}
}
}
Prints out:
%> gradle -q myTask
In plugin: unspecified
In build file: 1.0.0
Besides the how I really would like to know the why?
You set the property after you call
applyIf you move
To before the line
It should work
Edit
Following Peter’s answer, you can see that this works also:
To delay the evaluation of
$project.versionuntil evaluation of the build is complete