Programmatically determine Gradle version from within Gradle plugin
Asked Answered
C

2

5

How can I retrieve the version of Gradle itself programmatically from within a Gradle plugin?

Cirone answered 28/4, 2015 at 13:18 Comment(0)
C
6

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.
Cirone answered 28/4, 2015 at 13:32 Comment(0)
F
1

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.

Feces answered 1/10, 2019 at 11:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.