How specify gradle prerequisites (gradle version)?

Is there a way to specify gradle prerequisites, specifically minimal gradle version in build.gradle?

In Maven we have in pom.xml

<prerequisites>
    <maven>2.0.9</maven>
  </prerequisites>

I found there is way to validate Java version http://kaczanowscy.pl/tomek/2009-07/ant-gradle-and-maven-comparison-checking-build-prerequisites Not sure if it should be the same verbose check for gradle version. But if there is no other choice please provide appropriate snipped of the validation code.

Generally, you use the Gradle wrapper to do this. See http://gradle.org/docs/current/userguide/gradle_wrapper.html

We have some plans to make this a bit simpler in the near future.

I’m not sure how to use wrapper:

I tried to specify:

task wrapper(type: Wrapper) {
    gradleVersion = '1.0'
}

and then

...
gradleVersion = '1.1'
...
gradleVersion = '0.9'

but all of them work and don’t trigger any errors when I run it on 1.0-milestone-7.

The Gradle wrapper isn’t a validation mechanism. The idea is that everyone uses the wrapper (gradlew) to run builds. Then he automatically gets the version specified in the build script and doesn’t have to install anything.

I see, so I’m supposed to run:

gradle wrapper and then use:

./gradlew

to make use of all of this.

This is good to try things out with different versions of gradle, but you still have to install some gradle version initially and then finally install correct gradle persistently (system wide).

Only the person that updates the wrapper files (which is rarely needed) needs to have Gradle installed. All others will use the wrapper exclusively. This means that all it takes to upgrade everyone (devs, CI, etc.) to a new Gradle version is to edit gradle-wrapper.properties and commit it to source control.

1 Like

If you prefer a version check, you can easily implement it yourself:

def minGradleVersion = "1.0-milestone-7"
if (GradleVersion.current() < GradleVersion.version(minGradleVersion)) {
    throw new GradleException("Need Gradle version $minGradleVersion or higher")
}

You can turn this into a script or binary plugin for easy reuse.

I understand now, so gradle/wrapper/gradle-wrapper.* is supposed to be committed for it to be used by script. How can it be shared along with gradlew script between modules?

Thanks for the version check snipped - his is something I can use. Would be nice to have this check applied in declarative way (have it as built-in plugin) to match maven prerequisites plugin.

gradle/wrapper/gradle-wrapper.* is supposed to be committed for it to be used by script. How can it be shared along with gradlew script between modules?

The wrapper files only exist once per build, below the root project.

Just be aware that you’re using an internal class (‘GradleVersion’) that may change in the future.

And it seems Gradle.gradleVersion is the public alternative