Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking Groovy version Gradle is using

Tags:

gradle

groovy

I am running gradle and have previously been running groovy 1.76. I have now updated to groovy on my local machine (groovy_home points to groovy 2.1.2 etc).

$ groovy -version
Groovy Version: 2.1.2 JVM: 1.7.0_17 Vendor: Oracle Corporation OS: Linux

However, when I am running gradle commands (gradle test, classes, etc) I believe it is not building against groovy 2.1.2 but is actually still building against 1.76. (The reason I believe this, is that when I execute the classes I keep getting this error Upgrading Groovy 1.7 - 2.1 Incompatability, which is related to changes made post 1.76)

Is there a way to confirm which version of groovy my gradle install is building against?

Also, can anyone confirm where I should be configuring the groovy version for gradle?

like image 789
rhinds Avatar asked May 13 '13 17:05

rhinds


People also ask

Which Groovy version does Gradle use?

In order to support JDK 16 and keep up to date with the latest Groovy release, Gradle has been upgraded to use Groovy 3 in Groovy DSL build scripts. Groovy 3 comes with a new parser and host of other new features and capabilities that make interoperability with new Java features easier.

Is Gradle using Groovy?

gradle is a Groovy script. Thus it can execute arbitrary code and access any Java library, build-specific Gradle DSL and the Gradle API.

How do I check Groovy version in terminal?

Step16: To check whether Groovy is installed correctly or not, click on Command prompt and type groovy ? v and press enter. It will display the installer version of groovy of your system.

How do I change Groovy version?

If really you want to change the version of groovy in gradle, you might clone gradle from source, edit subproject/language-java/build. gradle. kts for java compiler, and same in any subprojects.


2 Answers

While trying to check the groovy version during gradle runtime, I found you can also print the Groovy version:

task version { 
  doLast {
    println "Gradle version: " + project.getGradle().getGradleVersion()
    println "Groovy version: " + GroovySystem.getVersion()
  }
}

As examples:

$ ~/usr/gradle-1.8/bin/gradle -q version
Gradle version: 1.8
Groovy version: 1.8.6

$ ~/usr/gradle-2.1/bin/gradle -q version
Gradle version: 2.1
Groovy version: 2.3.6

Note.- GroovySystem.getVersion() is available since Groovy 1.6.9

like image 135
Alberto Avatar answered Nov 05 '22 08:11

Alberto


Which Groovy library you are building against (and which Groovy compiler you are using) is determined by which Groovy library resides on the compile (or, in earlier Gradle versions, groovy) configuration. Typically a Groovy dependency is configured explicitly, but it may also be pulled in by transitive dependency management. (In case of a version conflict, the higher version wins by default. Which Groovy version(s) you have installed on your machine is irrelevant.) gradle dependencyInsight --configuration compile --dependency groovy should provide the answer.

Here is how a Groovy dependency is typically configured:

apply plugin: "groovy"

repositories {
    mavenCentral() // or some other repository containing a Groovy library
}

dependencies {
    // in Gradle 1.4 or earlier, replace 'compile' with 'groovy'
    compile "org.codehaus.groovy:groovy-all:2.1.2"
}
like image 20
Peter Niederwieser Avatar answered Nov 05 '22 08:11

Peter Niederwieser