Hack Classpath In Gradle

I recently tried this to fix the Classpath in Gradle for compiling and testing. Works for compiling, bombs for the testing though. The Gradle plugin integration using jna-3.2.7 blows up during unit testing when the older API is not loaded. What a mess. At least this snippet should help for other scenarios.

def fixTheCp(fc) {
    def jnaGoodJars = fc.filter {
        it.name == "jna-4.2.1.jar"
    return jnaGoodJars.plus(fc.minus(jnaGoodJars))

task("fixCompileCp") << {
    sourceSets.main.compileClasspath = fixTheCp(sourceSets.main.compileClasspath)
    sourceSets.main.runtimeClasspath = fixTheCp(sourceSets.main.runtimeClasspath)
task("fixTestCp") << {
    sourceSets.test.compileClasspath = fixTheCp(sourceSets.test.compileClasspath)
    sourceSets.test.runtimeClasspath = fixTheCp(sourceSets.test.runtimeClasspath)

compileJava.dependsOn fixCompileCp
testClasses.dependsOn fixTestCp
Download PDF
This entry was posted in Gradle, Snippets. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *