简体   繁体   中英

How to define Gradle version to use inside build.gradle?

Android new build system requires Gradle 1.10+ version. How to configure that inside build.gradle ?

I am aware that there is some wrapper configuration in other files, but I would like to make it more visible, as my goal is to prevent potential errors (time lost by team mates) in the future.

Compare to maven pom.xml

<prerequisites>
    <maven>3.0</maven>
</prerequisites>

ref Gradle version 1.8 is required. Current version is 1.6

You cannot configure the Gradle version in build.gradle . Instead, you'll have to configure the Gradle wrapper as explained in the link you gave. For additional information see the Gradle Wrapper chapter in the Gradle User Guide .

Configuring the Gradle Wrapper does not check that the correct Gradle version is used as in the POM snippet above, but it bootstraps the correct Gradle version for everyone that runs Gradle via the Gradle Wrapper (which includes the IDE), which is much more powerful. It would be easy to additionally check for the correct Gradle version in build.gradle (eg assert gradle.gradleVersion == "1.10" ), but typically this shouldn't be necessary.

Thank to the Peter who is likely working for GradleWare and is authoritative source.

Direct answer to the question is

assert gradle.gradleVersion >= "1.10" // android plugin 0.9 requires Gradle 1.10, 1.11

Updating Nodeclipse/Enide build.gradle template for classic Android project

Hmm.. You can configure the gradle version in a wrapper task

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

This assures You that (when using wrapper) all users will have the same version. There's no need for version checking, parsing and other..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM