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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
And this is how we run them with Gradle:
Wrapper script:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
${ROOT_DIR}/gradlew daoTest |
build.gradle:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task daoTest(type: Test) { | |
include "**/*DaoTest.class" | |
outputs.upToDateWhen { return false } | |
} |
Nice and simple!