How can I retrieve the version of Gradle itself programmatically from within a Gradle plugin?
Programmatically determine Gradle version from within Gradle plugin
Asked Answered
Just found out one can get at it using either
getProject().getGradle().getGradleVersion()
Javadoc and DSL reference for the Gradle core type which contains the version. Accordinng to the javadoc getVersion will never return null.
or
Plugin.class.getPackage().getImplementationVersion()
This is plain groovy/java class-based and depends on the classloader and provided Manifest.
This question appeared as the first result when I Googled for it.
There's a class - GradleVersion that'll do the job as well. So
GradleVersion.current()
will return the same as
getProject().getGradle().getGradleVersion()
EDIT
GradleVersion.current()
returns a GradleVersion
that after toString()
becomes something like Gradle 8.9
. GradleVersion.current().getVersion()
returns just the number, e.g. 7.6.3
.
© 2022 - 2024 — McMap. All rights reserved.