Eclipse-wtp deploys testcode to server (example provided)

This seems like a very basic problem, but I cannot find any information about it.

Example project:

build.gradle contains:

apply plugin: ‘war’ apply plugin: ‘eclipse-wtp’

All other files below are just empty placeholders:

├── build.gradle └── src

├── main

│ ├── java

│ │ └──

│ ├── resources

│ └── webapp


└── test

├── java

│ └──

└── resources

I run $gradle eclipse, import as existing eclipse project, add the project to my jboss server, and click on “Publish to server”.

$JBOSS/deployments/myproject.war/WEB-INF/classes now contains Main.class (expected) and Test.class. What is Test.class doing there? Why is testcode deployed? Have I missed something obvious?


Problem solved.

It seems as the Gradle 1.3 eclipse-wtp plugin doesn’t like SpringSource Tool Suite based on Eclipse 3.8.1. I switched to the version based on Eclipse 4.2.1 and now the problem is gone.

Uhm. Problem not solved. It’s not working. Same problem. It seemed to be working for a short while… :frowning:

I have now tried with “plain” Eclipse, SpringSource Toolsuite, cleared gradle caches etc, etc… Am I really the only one with these problems?

No, you’re not the only one having this problem. In fact, we’re facing problems where the test code is loading test versions of our Spring applicationContext xml files which define Apache CXF REST web services, and they don’t work at all.

We have a manual work around currently which involves setting separate output folders in eclipse, then going to the Deployment Assembly section of the project config, and removing the src/test/java, src/test/groovy, and src/test/resources items.

This affects both the .classpath and .settings/org.eclipse.wst.common.component files.

I’m going to keep searching, and see if anyone has come up with some gradle code to make these settings be correct, and if I can’t find anything, I’ll start trying to hack on these files with the EclipseWTP api.

1 Like

Good news, I was able to take advantage of the fact that the eclipseWtpComponent target does not attempt to add the test sourceSet to the Deploy Assembly. All that is necessary is to modify the generated .classpath using something like the following:

import org.gradle.plugins.ide.eclipse.model.SourceFolder
  eclipse.classpath.file.whenMerged { cp ->
    cp.entries.findAll { it instanceof SourceFolder && it.path.startsWith("src/test/") }*.output = "test-bin"

This just changes the eclipse output folders for any SourceFolder entries that start with src/test. If you have your test source set in a different structure, this will probably not work directly for you.