ClassNotFound using Gradle Test Kit


(Eric Hauser) #1

I’m writing some integration tests for a plugin using Nebula’s IntegrationSpec. I have a plugin that configures Protocol Buffers for a project and does something like this:

dependencies {
    compile gradleApi()
    compile ''

    testCompile ''
    void apply(Project project) {
        project.allprojects {
            it.getLogger().info("ProtosPlugin configuring ${}")

            it.apply plugin: ''

            protobuf {
                generatedFilesBaseDir = "$projectDir/generated_protos"

and then my test:

class ProtosPluginTests extends IntegrationSpec {

    def standardBuildFile = '''
        apply plugin: 'protocol-buffers'

    def 'can apply protos plugin and compile protos'() {
        buildFile << standardBuildFile


When I run this test from IntelliJ, it works just fine but when I do ./gradlew test it errors:

org.gradle.api.GradleException: Build aborted because of an internal error.
	at nebula.test.functional.internal.DefaultExecutionResult.rethrowFailure(DefaultExecutionResult.groovy:97)
	at nebula.test.IntegrationSpec.runTasksSuccessfully(IntegrationSpec.groovy:265)
	... 32 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
        ... 50 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
	... 93 more

It seems like the transitive dependencies from the plugin do not get loaded when running the tests but I can’t seem to figure out why. Any thoughts? I’ve tried forking the tests to avoid class loader issues, but that didn’t seem to help.

(Benjamin Muschko) #2

You might want to ask the question on the Nebula GitHub page. Nebula isn’t actually using TestKit under the covers as indicated by the title of your question. It’s using its own implementation. I’d actually recommend going with TestKit for writing functional tests these days as Nebula Tests is likely not going to maintained anymore. Should you run into the same issue with TestKit then we can have a deeper look.

(Eric Hauser) #3


My apologies. I just assumed that it used Test Kit under the covers and didn’t actually look. I’ll take a look at migrating over to Test Kit.