20

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?

1
  • Did you update PATH to make sure it was correct?
    – raffian
    May 13, 2013 at 17:05

4 Answers 4

33

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

1
  • I'd also add JavaVersion.current() in there somewhere.
    – MarkHu
    Nov 11, 2022 at 19:14
10

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"
}
1
  • Perfect thanks - was being an idiot and completely missed the groovy dependency declaration!
    – rhinds
    May 14, 2013 at 9:30
5

in windows you can check it using: gradlew --v

------------------------------------------------------------
Gradle 6.2
------------------------------------------------------------

Build time:   2020-02-17 08:32:01 UTC
Revision:     61d3320259a1a0d31519bf208eb13741679a742f

Kotlin:       1.3.61
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          15.0.2 (Oracle Corporation 15.0.2+7-27)

on linux the command will be : gradle --v

0

I'm using osx

gradle --v


------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------

Build time:   2022-08-05 21:17:56 UTC
Revision:     d1daa0cbf1a0103000b71484e1dbfe096e095918

Kotlin:       1.6.21
Groovy:       3.0.10
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.4.1 (Homebrew 17.0.4.1+1)
OS:           Mac OS X 12.4 x86_64

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.