I have a Gradle 6.0.1
project. The build.gradle
(excerpt) looks like:
plugins {
id "application"
id "com.github.edeandrea.xjc-generation"
id "eclipse"
id "idea"
id "java"
id "org.springframework.boot"
}
...
dependencies {
implementation platform("org.springframework.boot:spring-boot-dependencies:${property("spring-boot.version")}")
// ...more stuff here
}
// ...more stuff here
I'm managing all the plugin versions in settings.gradle
:
pluginManagement {
plugins {
id "application"
id "com.github.edeandrea.xjc-generation" version "1.0"
id "eclipse"
id "idea"
id "java"
id "org.springframework.boot" version "${spring-boot.version}"
}
}
rootProject.name = "spring-core"
...and I usually put the artifact versions in gradle.properties
:
#
# Dependency Versions
oracle.version = 18.3.0.0
spring-boot.version = 2.2.1.RELEASE
#
# Gradle Settings
org.gradle.configureondemand = false
org.gradle.daemon = false
#
# System Settings
systemProp.file.encoding = UTF-8
systemProp.sun.jnu.encoding = UTF-8
Now the problem is I can't read dot-properties in settings.gradle
(from gradle.properties
) in the same way I do it inside build.gradle
— I already tried using ${property("spring-boot.version")}
.
Is there any way to achieve that? I can easily change the key to something like springBootVersion
and it works, but I wonder if there is a way to have in the way I currently have it: spring-boot.version
.
use getProperty("spring-boot.version")
simple gradle project with additional variants
task test{
doLast {
//success
println project.property('aaa.bbb.ccc')
println project.'aaa.bbb.ccc'
println getProperty('aaa.bbb.ccc')
//failure: Could not get unknown property 'aaa.bbb.ccc' for task ':test' of type org.gradle.api.DefaultTask
println property('aaa.bbb.ccc')
}
}
gradle.properties
aaa.bbb.ccc=12345
property('aaa.bbb.ccc')
fails because it tries to get property on current object (task) but aaa.bbb.ccc
defined for project
however project.property('aaa.bbb.ccc')
succeeds because it should
project.'aaa.bbb.ccc'
is the same as project.getProperty('aaa.bbb.ccc')
in groovy
project.getProperty('aaa.bbb.ccc')
works because of groovy basic object GroovyObject
(IHMO)
and getProperty(name)
without prefix actualy located in org.gradle.groovy.scripts.BasicScript and not really documented...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With