Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why run 'gradle clean build' instead of 'gradle build'?

Why would I run gradle clean build instead of gradle build?

From what I understand, Gradle can detect source changes and update the final artifacts if needed. So why would I still need to clean?

like image 233
marius bardan Avatar asked Mar 13 '15 09:03

marius bardan


People also ask

What does Gradle clean build do?

clean will delete a build directory, all your classes will be removed for a fresh compile. assemble will create an archive (JAR) file from your Java project and will run all other tasks that require compile, test and so on.

What does Gradle clean test do?

If you're only interested in rerunning the tests then another option would be to make gradle clean the tests results before executing the tests. This can be done using the cleanTest task. Some background - the Java plugin defines a clean tasks to each of the other tasks.

Where should I run Gradle commands?

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.


Video Answer


1 Answers

The clean task is defined by the java plugin and it simply removes the buildDir folder, thus cleaning everything including leftovers from previous builds which are no longer relevant. Not doing so may result in an unclean build which may be broken due to build artifacts produced by previous builds.

As an example assume that your build contains several tests that were failed and you decided that these are obsolete thus needs to be removed. Without cleaning the test results (using cleanTest task) or the build entirely (by running the clean task) you'll get stuck with the failed tests results which will cause your build to fail. Similar side effects can happen also with resources/classes removed from the sources but remained in the build folder that was not cleaned.

like image 130
Amnon Shochot Avatar answered Sep 21 '22 08:09

Amnon Shochot