Is gradlew required for Travis CI to work?

I am trying to configure CI for a project that I am working on, and I am wondering if we really need to commit the gradlew and / or gradle.bat to make it work.

Is there a workaround for this, or just files for this?

+5
source share
3 answers

A gradlew script gradlew not required to create a Gradle project in Travis CI.

Probably the best alternative is to use the pre-installed Gradle to install the Gradle wrapper. Here's what a simple build.gradle looks like:

 apply plugin: 'java' check.doFirst { println "Running gradle v${project.gradle.gradleVersion}" } task wrapper(type: Wrapper) { gradleVersion = '3.4.1' } 

If you use this build file with the standard Travis handle, this will not work. It will just use gradle to start your build. However, if you added a shell task to the handle:

 language: java jdk: - oraclejdk8 before_install: gradle wrapper 

First, Travis runs the shell task, and then correctly detects that gradlew present, and use it to start the build.

However, this approach has a flaw that could disrupt your build. If you use some functions in Gradle that were implemented after the preinstalled version of Gradle, the gradle wrapper step will fail. An example of such a function is the S3 maven repository, which was introduced in version 2.4. I suppose.

To prevent this, you can transfer the shell task to a separate assembly file, say wrapper.gradle :

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

And change the .travis.yml file to:

 language: java jdk: - oraclejdk8 before_install: gradle -b wrapper.gradle wrapper 

That should do it. This installation uses the pre-installed Gradle to install the shell without changing the main assembly script.

You can see the build example here and this is the entire GitHub repository .


Note. There is another way. You can use the before_install step to install the required version of Gradle from a download distribution, or possibly using the Debian package system. However, this requires sudo privileges. Such virtual machines take a lot of time (about 30 seconds?).

Another thing, I mentioned this in a comment on another answer, if you pass a gradlew script, you also need banners and shell properties. An ATM is a binary file, and its inclusion in version control is sometimes seen as contradictory. Therefore, if you use the solution described above, you can also omit gradle folder.

+4
source

This is not necessary because it is already preinstalled for Java and Android projects.

However, this is the recommended path because the installed version depended on the virtual machine creation date, probably outdated.

You can try and check the version with the gradle --version command.


Update # 1

I demonstrated that my answer is correct for your MaterialSearchView :

Gradle version 2.2.1 is already pre-installed, so the Gradle wrapper is optional, but it is recommended to use it because your project requires version 2.14.1.

 script: - gradle clean build 

I also demonstrate that the selected answer is correct, based on an incorrect assumption. Try to use an unnecessary file and breaking the assembly does not make this file mandatory, just do not use it and do not delete the chmod line.

enter image description here

You can check here the required version of Gradle for each version of the Gradle plugin, in your case for version 2.2.3 plugins require Gradle 2.14.1 +

+2
source

Yes, these files are necessary.

I determined this with a little trial and error. I removed them from a branch in one of my personal projects and pushed them to GitHub, and the travis build failed.

If you're curious about what the magazine looks like, check out this point .

As you can see below, this is a mistake:

 chmod: cannot access `gradlew': No such file or directory The command "chmod +x gradlew" failed and exited with 1 during . 

Minor editing: I tried using it with the gradlew file, but not with the gradlew.bat file. This worked for easy cleaning / assembly, but when Travis tried to run the emulator, it hung for more than 10 minutes.

TL DR use both files.

0
source

Source: https://habr.com/ru/post/1265509/


All Articles