NoClassDefFoundError - Generated classes


(Simone Vratogna) #1

Hello I have a gradle project that used to work correctly in eclipse (neon 3) with an older version of buildship, recently I updated to version 2.2.1 and cannot run my unit tests anymore.
The problem lies in the fact that, using querydsl, there are a bunch of generated classes (that are correctly added to the project classpath) that now are not found anymore when trying to run the tests.
Running the tests just using gradlew is ok.
I have read something concerning the fact that the now the classpath used by eclipse and that used by buildship have totally diverged so I see the classes in eclipse’s classpath but are not available for buildship’s. The problem is that I have no idea on how to solve this… :slight_smile:


(Donát Csikós) #2

Buildship 2.2 introduced runtime classpath separation which probably causes your problem. The works the following way: it checks what Gradle source sets the executed main() method or test class belong to and filters the unrelated entries from the runtime classpath. It’s a bit tricky to debug, so I’d suggest you create minimal example exhibiting the problem and we’ll have a look.


(Donát Csikós) #3

Another idea would be to disable the classpath separation. You can do that by removing the gradle_scope and the gradle_used_by_scope attributes from the classpath entries. You can customize the classpath entries in the eclipse.classpath.file.whenMerged block:

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
        file {
            whenMerged {
                entries.each { entry ->
                    if (entry instanceof org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) {
                        entry.entryAttributes.remove('gradle_scopes')
                        entry.entryAttributes.remove('gradle_used_by_scope')
                    }
                }
            }
        }
    }
}

(Simone Vratogna) #4

I’ll try to create an example project asap. In the meanwhile, the solution of disabling class separation works, thank you!