Friday, 15 April 2016

So.....Gradle

My previous post mentioned that we are currently using Maven as our build system but looking at moving across to Buck. Well, there has been a slight change of plan and we've moved to using Gradle. The main reason we opted for Gradle over Buck is its integration with Intellij, which was some what of a pain point when I was working at LMAX.

Migrating from Gradle to Maven was super easy, and has allowed us to simplify the various tests we had defined; Maven becomes very complicated if you try and do anything beyond their defined build tasks, which was very annoying for us as we have multiple test definitions being unit tests and integration tests (dao, acceptance, benchmark, perf, compatibility.....). This had resulted in some serious hackery (note: completely my fault).

As an example, this is how we ran DAO tests in the Maven world:

local testDirectory=test-classes
local testDirectoryLength=$((${#testDirectory} + 1))
local mavenRepository=$(eval echo ~$USER)/.m2/repository
#Find test classes, and convert them their package location (rather than file system)
local testsClasses=$(find . -path *target/*DaoTest.class | grep -v "/DaoTest")
local tests=""
for test in ${testsClasses}; do
tests=${tests}" "$(echo ${test:$(($(echo ${test} | grep -b -o ${testDirectory} | cut -d: -f1) + ${testDirectoryLength}))} | sed -e 's/\//\./g' | sed -e 's/.class//g')
done
#Build the class path....
local jars=$(JARS=($(find deploy -name *.jar)); IFS=:; echo "${JARS[*]}")
local clazzs=$(CLAZZ=($(find . -name ${testDirectory})); IFS=:; echo "${CLAZZ[*]}")
local classpath=${mavenRepository}/junit/junit/4.12/junit-4.12.jar:${jars}:${clazzs}
${OPT_DIR}/jdk/bin/java -cp ${classpath} org.junit.runner.JUnitCore ${tests}
view raw maven.sh hosted with ❤ by GitHub

And this is how we run them with Gradle:

Wrapper script:
${ROOT_DIR}/gradlew daoTest
view raw wrapper.sh hosted with ❤ by GitHub

build.gradle:
task daoTest(type: Test) {
include "**/*DaoTest.class"
outputs.upToDateWhen { return false }
}
view raw build.gradle hosted with ❤ by GitHub

Nice and simple!

No comments:

Post a Comment