Specify gradle minimum version

Hi,

with the introduction of gradle2, it is more common now to see gradle projects fail because the user attempts to run the build with the wrong gradle version. I understand by convention every project should ship a suitable gradle version using the gradle wrapper. Still, it might be good to have a standard required version declaration that can be used to provide a useful error or warning. Else some arbitrary error occurs which can only scare new users.

Something like

GradleVersion.require(2.x)

which would output an error or warning if the project is build using a different Gradle version. I know any user can hack something like this using the GradleVersion class, but the point here is about establishing a best practice in the ecosystem.

This idea is also inspired by cmake_minimum_required (VERSION …)

http://www.cmake.org/cmake/help/v3.0/command/cmake_minimum_required.html

It’s a planned feature. ‘GradleVersion’ is an internal class (use ‘gradle.gradleVersion’ instead).

Interesting. GradleVersion is not in an “internal” package, is there any other convention to know which classes are considered internal? E.g. are only classes below org.gradle.api considered “public”?

Only classes listed in the Javadoc/Groovydoc are part of the public API.

Today I lost some time because I was trying to build a Gradle 2.x version with 1.x. It fails with message:

‘java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling’

I want it to fail with a message like: ‘ERROR This project requires Gradle 2.0.0 or higher.’

Is there a way to achieve this with a snippet in build.gradle?

I think this will make adoption of new Gradle features a lot easier, and increases the reproducability of builds.

Based on the answer before… Consider something like

if (gradle.gradleVersion.startsWith(‘1’)) {

throw new GradleException(‘This project requires Gradle 2.0.0 or higher.’) }

Similar question here: http://forums.gradle.org/gradle/topics/is-there-a-way-to-programmatically-ensure-a-minimum-gradle-version-using-non-internal-gradle-apis