Monday, March 20, 2017

Which Gradle commands do which things?

To get started you only need to know a couple of tasks.
  1. gradlew clean
  2. gradlew test
  3. gradlew build
You may have noticed that after you ran gradlew build, a new directory was created in your project's root directory named 'build'. This directory contains all of the artifacts resulting from building your project.
  • build/classes - The compiled Java classes
  • build/test-results - The raw results of your unit tests
  • build/reports - An html report displaying the results of your unit tests
  • build/libs - The java-quickstart.jar library for your project
In order to clean up the files generated by the build process run the following command:
gradlew clean
This should result in the 'build' directory being deleted. At this point your project is back to its initial state.
Next try running this command:
gradlew test
This command instructs Gradle to compile your Java source files, execute your unit tests, and generate the test report. If all of your tests passed you should see a 'BUILD SUCCESSFULL' message.
Finally, run the build command again:
gradlew build
This command will instruct Gradle to compile your Java source files, execute your unit tests, generate a test report, and assemble your jar. You may notice that the some of the steps in the build output are labelled 'UP-TO-DATE'. Gradle is smart enough to keep track of what steps it has already executed and only execute them again if something has changed.
Now try to execute this command:
gradlew clean build
The result of running this command is the same as when you just the gradlew build command. However, notice that most of the build steps in the console's output no longer are marked as 'UP-TO-DATE'. This is because you told Gradle to clean up the build directory before running the build. This means that Gradle had to recompile the sources, rerun the tests, regenerate the test report and finally generate the jar.
A Basic Workflow
To start developing your library, you can follow the simple workflow described below.
  1. Develop a new feature with unit tests
  2. gradlew test
  3. If tests fail, fix the code and go back to step 2
  4. If you need to add more features, go back to step 1
  5. gradlew clean build
At the end of this workflow you should have a unit tested version of 'java-quickstart.jar' that is ready for use.

Resource Link:
  1. https://kchard.github.io/java-quickstart/

No comments:

Post a Comment