If I specify in ‘build.gradle’ that belongs to the root:
allprojects {
version=“1.0-SNAPSHOT”
}
Then I want to use the same version property in a subproject like that:
dependencies {
compile group: 'com.myproject.module', name: 'first', version: allprojects.version
}
In Gradle 2.6: it will put ‘[1.0-SNAPSHOT]’
In Gradle 2.7: it will be ‘1.0-SNAPSHOT’ without brackets
What can be the reason for that? Is that due to some gradle issues in
2.6? In gradle 2.2.1 - it also works fine (without brackets).
Lance_Java
(Lance Java)
September 29, 2015, 2:31pm
2
Short answer:
For a local project dependency, just use project(…)
dependencies {
compile project(':first')
}
Long answer:
My guess is that allprojects.version
is a List and the toString() method is adding the brackets. You could have used the following in a subproject
dependencies {
compile group: 'com.myproject.module', name: 'first', version: project.version
}
Or less verbose as:
dependencies {
compile "com.myproject.module:first:${project.version}"
}
But my first answer is best for a local project dependency
Thanks. Strange that it is treated differently in different versions of Gradle
Lance_Java
(Lance Java)
September 30, 2015, 8:11am
4
It looks like something changed slightly but I wouldn’t lose any sleep over it as using allprojects.version
is wrong.
I think what you are missing is that
allprojects {
version="1.0-SNAPSHOT"
}
Is the same as
allprojects({ Project p ->
p.version="1.0-SNAPSHOT"
})
Whereas allprojects.version
is the same as getAllProjects().version
You can see from the [project interface] (https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/Project.java ) that getAllProjects()
returns a Set<Project>