Checking Groovy version Gradle is using

前端 未结 2 1068
慢半拍i
慢半拍i 2021-02-13 01:18

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

$ g         


        
相关标签:
2条回答
  • 2021-02-13 01:44

    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"
    }
    
    0 讨论(0)
  • 2021-02-13 01:52

    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

    0 讨论(0)
提交回复
热议问题