Search code examples
gradlegradle-plugin

Programmatically determine Gradle version from within Gradle plugin


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


Solution

  • 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.