Skip to content

Using Gradle

bclinthall edited this page Mar 7, 2017 · 10 revisions

Using gradle

When you clone our git repo, if you are in a branch that is a gradle project (try the json branch as of 3/7/17 1:00pm), you will have a file called gradlew and another called gradlew.bat. I'm pretty sure that if you execute either of those, all the gradle stuff you need will be downloaded, if gradle is not already installed on your system. It looks like if you don't have gradle installed, then instead of using the gradle command described below, you need to call gradlew. So, instead of gradle test call ./gradlew test, if you are in the directory that contains .gradlew. Otherwise call <project-root>/gradlew test. Or just add gradlew to your path.

Gradle looks in src/main/java for regular classes and src/test/java for unit test classes. As long as you put stuff in the right places, it gets compiled and tested (I think).

Run gradle test to test. It won’t mention the tests unless one fails. If one fails, it will tell you which one, and also tell you how to get more information.

gradle build builds the project into a jar file. The jar will be at <project-root>/build/libs/scatt.jar You can run the jar by going there and calling java -cp scatt.jar Scatt

gradle check runs checkstyle. The checkstyle.xml should be in <project-root>/config/ When checkstyle fails, a report is generated and stored in <project-root>/build/reports/checkstyle/

All the magic happens in the build.gradle file in the project root. I added one line there to enable checkstyle in gradle, and another to allow us to use org.json.* for parsing. It really feels like magic.

There is now a Gradle eclipse plugin. http://www.vogella.com/tutorials/EclipseGradle/article.html

For future reference

If you have gradle installed, you can initiate a gradle project with gradle init --type java-application. Or you can set the type to java-library if that is more appropriate. That will set up a directory structure, a build.gradle file, and even a dummy class and dummy test class. It doesn't auto generate a .gitignore, so google "Gradle Java gitignore" and follow the advice before committing a bunch of stuff you don't really want git tracking.

Clone this wiki locally