I am new to gradle and have some question about project properties.
I need to declare spring boot dependences at multiple locations in my build.gradle and I\'d like
Because the buildscript
block is evaluated first, before springBootVersion
has been defined. Therefore, the variable definition must go in the buildscript
block before any other definitions:
Source Here
buildscript {
ext {
springBootVersion = '1.1.9.RELEASE'
}
print project.springBootVersion //Will succeed
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}")
}
}
This will not work.
First of all buildscript
block is evaluated at the very beginning, before any other part of groovy script. Hence, properties defined in ext
block just does not exist at that time.
Secondly, I'm unsure about if exchanging properties between buildscript
and other part of script is possible.
Moving the ext
block inside the buildscript
block solves the problem for me. Not sure if this is officially supported though, as it's effectively configuring project.ext
from the (very special) buildscript
block.