9

What is the Gradle analog for Maven's --show-version option?

 -V,--show-version                      Display version information
                                        WITHOUT stopping build

Output includes Maven, Java and OS versions:

Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: D:\Progs\maven\apache-maven-3.1.1
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_11\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"  

-version stops the build. Both lines below give the same result: version only

gradle build -version
gradle -version build
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • 1
    Try `gradle -version` – Opal Apr 18 '14 at 12:03
  • '-version' stops the build. – Paul Verest Apr 18 '14 at 12:18
  • Don't understand? If You want gradle to display version use `gradle -version` command. It has nothing to do with `build`. – Opal Apr 18 '14 at 12:26
  • 1
    `--show-version` option is usually added in CI environment to add env details into log, as those enthronements are different. `--show-version` DOES NOT STOP BUILD. And you do not need modify 10, 100 etc of build configurations. – Paul Verest Apr 18 '14 at 12:29
  • Ok. Didn't know that. In gradle there's no such switch. You can write custom task for it. – Opal Apr 18 '14 at 12:32

6 Answers6

8

You can use:

gradle -v

This is the output:

------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
Build time:   2013-12-17 09:28:15 UTC
Build number: none
Revision:     36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.7.0_51 (Oracle Corporation 24.51-b03)
OS:           Linux 2.6.32-042stab079.5 amd64

If you use it in CI environment, it doesn't stop the build.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
7

Just add this line at the very beginning of build.gradle script:

println GradleVersion.current().prettyPrint()

It won't stop the build and print all the required info (I hope so). Unfortunately haven't found docs for this class.

EDIT

Note for newer versions of Gradle: As prettyPrint is dropped from some gradle version, you can just add this line at the very beginning of build.gradle script:

println GradleVersion.current().getVersion() + " - " + GradleVersion.current().getBuildTime() + " - " + GradleVersion.current().getRevision() + GradleVersion.current().isSnapshot() ? " - is snapshot" : ""
Opal
  • 81,889
  • 28
  • 189
  • 210
  • 2
    prettyPrint is dropped from some gradle version. Currently you could something like println GradleVersion.current().getVersion() + " - " + GradleVersion.current().getBuildTime() + " - " + GradleVersion.current().getRevision() + GradleVersion.current().isSnapshot() ? " - is snapshot" : "" – gkephorus Sep 01 '16 at 09:18
  • 3
    Since Gradle 5.0 the internal class `GradleVersion` is not visible anymore. – Matthias Braun Nov 28 '18 at 11:19
6

Since Gradle 5.0, GradleVersion is no longer accessible. Use

project.getGradle().getGradleVersion()

instead.

For example:

task printGradleVersion() {
    def gradleVersion = project.getGradle().getGradleVersion()
    println "Gradle version: $gradleVersion"
}

See the docs for more information.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
1

As prettyPrint is dropped from some gradle version, you can just add this line at the very beginning of build.gradle script:

println GradleVersion.current().getVersion() + " - " + GradleVersion.current().getBuildTime() + " - " + GradleVersion.current().getRevision() + GradleVersion.current().isSnapshot() ? " - is snapshot" : ""
gkephorus
  • 1,232
  • 18
  • 31
1

Please input gradle -v on the terminal and the output should look like the image below

enter image description here

0

Did using org.gradle.internal, that is definitely not future ready. And not as much info as in gradle -version

apply plugin: 'java'

println "Gradle "+gradle.gradleVersion
println org.gradle.internal.jvm.Jvm.current()

repositories {
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • `org.gradle.internal` is dedicated not to be used by external users (can be changed for instance). As I said You can write custom task and most of info You need can pulled out from `System` class - see http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html – Opal Apr 18 '14 at 14:55