Buildship / Deploy Assembly / Test classes

I have a multi-module project I am trying to better integrate with Eclipse using buildship. Buildship imports the projects just fine and after removing the java plugin from the EAR project, I am able to attempt to deploy my EAR to Websphere (liberty). The deploy never completes because I get NoClassDefFoundError exceptions due to missing Test classes.

I have not done any customization of the source sets for this project at all so all the tests are in src/test/java for each sub project that has tests. The deploy assembleis properties page for all my sub projects do not show these src folders as contributors so I have no clue how these test classes are showing up for deployment when using eclipse.

Is there a configuration step that I am missing that is not done by the eclipse-wtp plugin? I have 1.0.21 of Buildship and gradle 3.3.

Hey Joshua,

this is most probably because the eclipse-wtp plugin includes the default output location (/bin) in the deployment assembly and both main and test sources are compiled into that folder by default. I think you can work around this by changing the output path of the test sourceset:

eclipse.classpath.file.whenMerged {
    entries.findAll { it.path.startsWith("src/test/") }*.output = "test-bin"
}
```
Cheers,
Stefan

Thanks, we may have seen the same stack overflow answers. I ran across this same solution as well.

Just to add to this, by putting the above into the build file, eclipse-wtp will configure the org.eclipse.wst.common.component file to include the those /src/test folders as separate wb-resource entries. To prevent the plugin from including your test output directories you need an additional little bit of code:

eclipse.wtp.component.file.whenMerged { wtpComponent ->
	wtpComponent.wbModuleEntries.removeAll {
		it instanceof WbResource && it.sourcePath.startsWith('/src/test')
	}
}

With the above two snippets, eclipse produces an ear with no test classes

Im one step closer :slight_smile:

My finalized bit of code that makes sure src/test is not in eclipse-generated ear files is below:

import org.gradle.plugins.ide.eclipse.model.WbResource

eclipse {
    classpath.file.whenMerged {
        entries.findAll {
            it.path.startsWith('src/test')
        }*.output = 'bin-test'
    }
    
    wtp.component.file.whenMerged {
        wbModuleEntries.removeAll {
            it instanceof WbResource && it.sourcePath.startsWith('/src/test')
        }
    }
}

Makes me wonder if this is something that the eclipse plugins could be doing as everyone whose doing testing and using the default java source sets will need this…

1 Like

Yes it probably should, feel free to open an issue for that on GitHub. Pull requests are also welcome :slight_smile:

Issue created at the very least!