When I try to read the value from project.version
and project.description
I expect that is act on same way as when I’m reading project.name
.
In example from picture in task ‘bootRun’ for project.name
I’m getting name of subproject, and that is as expected.
But when I’m reading project.version
, I’m always getting a version of the parent project, not from subproject, as I’m getting the name of subproject.
The same behavior is with project.description
.
I can’t reproduce the issue you are reporting. Here’s my example:
settings.gradle
include 'a', 'b', 'c'
build.gradle
version = '1.0'
allprojects {
task printVersion {
doLast {
println project.version
}
}
}
project(':b') {
version = '5.5'
}
Command line:
$ gradle :printVersion
:printVersion
1.0
$ gradle :a:printVersion
:a:printVersion
unspecified
$ gradle :b:printVersion
:b:printVersion
5.5
As you can see the proper project versions are reflected. I guess the reason you are resolving the wrong project version is because you reference the root project instead of the actual subproject. Try to actually assign a closure parameter when referencing the subproject.
subprojects { subproject ->
println subproject.version
}
Hi, thx for suggested solution.
I found out that I have a problem when I’m trying to add bootRun
task in subproject, and in that case that task is getting information from the parent.
If I create custom tasks in subproject, then that task is getting proper values from project
variable.
Kind regards,
Davor