In gradle, how to use a variable for a plugin version?
Solution 1:
You cannot use variable here:
Where «plugin version» and «plugin id» must be constant, literal, strings. No other statements are allowed; their presence will cause a compilation error.
Solution 2:
As of Gradle 5.6, you can declare your plugin versions in the gradle.properties
file, and reference these properties in plugins
block.
For example, the gradle.properties
file:
springBootVersion=2.2.0.RELEASE
the plugins
block in build.gradle
:
plugins {
id "org.springframework.boot" version "${springBootVersion}"
}
See: https://github.com/gradle/gradle/issues/1697#issuecomment-506910915.
See also:
- https://docs.gradle.org/5.6/release-notes.html#central-management-of-plugin-versions-with-settings-script
- https://docs.gradle.org/5.6/userguide/plugins.html#sec:plugin_management