Why run 'gradle clean'?

半腔热情 提交于 2019-11-27 20:11:27

问题


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?


回答1:


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.




回答2:


It removes the build directory. (Build contains the output of the gradle operation)




回答3:


Other build tools like buck will detect that some tests are removed and won't run them without the needs to run clean target. I think this is pitfall of gradle.



来源:https://stackoverflow.com/questions/29028748/why-run-gradle-clean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!