I have a multi-project build with several sub projects and I want to use the gradle wrapper.
What's the idiomatic way to do this?
Should I configure the wrapper in every subproject by adding the following code to build.gradle
in the root?
allprojects {
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
}
But then, do I check all the gradlew.bat
, gradlew.sh
, gradle/wrapper/gradle-wrapper.jar
, etc. files from all the subproject directories into version control?? That seems inefficient, but if I don't then how can I execute ./gradlew.sh
in a sub project directory? What is the preferred way to use gradle wrapper in a subproject?
Do developers just use the gradle installed on the filesystem for this case?
The most important question is the first: what's the idiomatic way to do this?
To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … e.g. gradlew clean allTests.
1. No need to install gradle locally. The gradlew script doesn't rely on a local Gradle installation. It goes and fetches a Gradle installation from the internet the first time it runs on your local machine, and caches it.
The difference lies in the fact that ./gradlew indicates you are using a gradle wrapper. The wrapper is generally part of a project and it facilitates installation of gradle.
Overview. Gradle is commonly used by developers to manage their project's build lifecycle. It's the default choice of build tool for all new Android projects. In this tutorial, we'll learn about Gradle Wrapper, an accompanying utility that makes it easier to distribute projects.
You should just have the wrapper task outside of the allprojects block so you only have one gradlew.bat
, gradlew.sh
, and gradle/wrapper/gradle-wrapper.jar
at the top level of your project structure.
You can run the ./gradlew tasks --all
to verify the wrapper can see the subproject tasks
Or you can run the ./gradlew <subproject_name>:tasks
command to view just one subproject's tasks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With