2

We have here a JEE Vaadin project in eclipse (neon) IDE and as build system we use gradle. But we have a problem with our test classes. If we build our war/ear with gradle all is fine. The test classes are not part of the war archive.

But if we want to deploy the ear project on the wildfly server from inside of eclipse it seems that the test classes are part of the war archive. Because while deploy the ear we getting some errors like:

...
Caused by: com.google.common.util.concurrent.ExecutionError: com.google.common.util.concurrent.ExecutionError: java.lang.LinkageError: Failed to link com/coco_on/docFlow/vaadin/admin/TestAdminRoles (Module "deployment.DFl_EAR.ear.DFl_Vaadin.war:main" from Service Module Loader)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
    at org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java:49)
    at org.jboss.weld.resources.DefaultReflectionCache.getBackedAnnotatedTypeAnnotationSet(DefaultReflectionCache.java:169)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.getAnnotations(BackedAnnotatedType.java:112)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.getAnnotation(BackedAnnotatedType.java:98)
    at org.jboss.weld.bootstrap.BeanDeployer.processPriority(BeanDeployer.java:105)
    at org.jboss.weld.bootstrap.BeanDeployer.processAnnotatedTypes(BeanDeployer.java:174)
    at org.jboss.weld.bootstrap.BeanDeployment.createTypes(BeanDeployment.java:224)
    at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:381)
    at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:76)
    at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:92)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    ... 3 more
Caused by: java.lang.NoClassDefFoundError: com/vaadin/testbench/TestBenchTestCase
...

TestAdminRoles is one of our test classes and TestBenchTestCase is one of the needed classes in a test framework (Vaadin Testbench). But this test framework will be not found and this is also ok, because we don't want link this library into the ear/war.

We have also read this post: https://stackoverflow.com/a/9820317/1465758

So we have removed the src/test/ directories from the deployment and set a different bin directory for the test source directories. But without success. The error above is still there.

And so my question is: How can I configure eclipse so that eclipse don't put the compiled test classes to the war file?

Community
  • 1
  • 1
Steffen
  • 2,500
  • 4
  • 31
  • 47

1 Answers1

0

You need to change the output-folder of the sourcefolders for test-sources and remove the test-directories from the deployment assembly.

This should be added to the build.gradle. (the eclipse-plugin needs to be also applied)

eclipse {
    // change output dir of the sourcefolders
    classpath.file.whenMerged {
        entries.findAll { it instanceof org.gradle.plugins.ide.eclipse.model.SourceFolder }.each { 
            it.output = 'build/eclipse/' + (it.path.startsWith('src/test') ? 'output-test' : 'output')
        }
    }

    // removes test dirs from deployment assemble
    wtp.component.file.whenMerged {
        wbModuleEntries.removeIf {
            it instanceof org.gradle.plugins.ide.eclipse.model.WbResource && it.sourcePath.startsWith('/src/test')
        }
    }
}

Code Source (small changes where applied)
In this example the output-directory from non test-sources are also changed, that all output-directories are inside the build-directory from Gradle.

jmattheis
  • 10,494
  • 11
  • 46
  • 58