18 August 2015

Recently, I attempted to convert a project that uses CGLIB and Spock Framework to execute unit tests to use Java 8 source and target versions. When I went to run the unit tests, I was met with a nasty java.lang.IllegalArgumentException. Some quick internet searching showed that there is an existing issue with the currently released version of CGLIB and the version of the ASM library it depends on. Despite pleas from the community, an updated version of CGLIB with Java 8 compatibility has not yet been released. However, there are commits on the project’s trunk that add Java 8 compatibility. Luckily, a quick look at the Spock Framework source code showed me how to get around this issue. The trick is to use JitPack.io as a Maven repository in your build script to build a particular commit hash of the project and expose it as a dependency for your project. After some digging through the source, I determined that commit 52e118aca4 is the proper one to use. To use this version of CGLIB in your build.gradle file, you simply need to add the following:

repositories {
    // ...
    maven { url "https://jitpack.io" }
}

dependencies {
    testCompile 'com.github.cglib:cglib:52e118aca4'
    testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
}

You can generate this information using JitPack.io itself by going to the following URL: https://jitpack.io/#cglib/cglib/52e118aca4. Now, my project will get JitPack.io to build the custom release of CGLIB without me needing to build and push it into a repository!

comments powered by Disqus