4

I have the following default configuration for the Maven Failsafe Plugin:

  <plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.20</version>
    <executions>
      <execution>
        <id>default-integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
      <execution>
        <id>default-verify</id>
        <phase>verify</phase>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

The documentation states that the default classpath includes both the target/test-classes and target/classes directories, in that order. However, when I run mvn clean install or mvn integration-test, I don't see the classes folder as part of the classpath. This is causing test failures as I am injecting a class from my source into the test and I get a NoClassDefFound exception.

Here is the verbose output:

[DEBUG] test(compact) classpath: test-classes package.jar javax.inject-1.jar cdi-api-1.2.jar ...

As you can see the classes folder should have been added before the project dependencies, but it is not.

However, when I run the mvn failsafe:integration-test goal specifically, instead of a phase, then the classpath includes classes immediately after test-classes and the tests are successful, which is consistent with the documentation.

What am I not understanding about the build process? Why is the classpath different when running the phase as opposed to running the goal? How can I get classes in the classpath even when running the phase?

Charles
  • 4,372
  • 9
  • 41
  • 80
  • First I would suggest not to define the plugin configuration like that just do it as state in the [usage documentation](http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html) no own id's etc.. furthermore you see the entry in your debug out: `package.jar` ? What exactly is this? This is the code you have under `target/classes` as packaged in a jar file...BTW: Can you attach full log output of your build? Is there a good reason why you are using such an older version of surefire/failsafe plugin? BTW: Are you using the same version for surefire and failsafe plugin? – khmarbaise Jun 06 '18 at 15:52
  • I am actually not defining it like that, that is what I copied from the effective-pom so I think Maven is adding those default IDs. I will look at the `package.jar`, I don't see that when I run the goal directly so maybe it could contain the source classes. But then I would wonder why I'm still getting the `NoClassDefFound` exception...? – Charles Jun 06 '18 at 15:54
  • Ah but you didn't wrote that...Yes the id's are added by default that's true. Can you show the code which causes the issues ? Or do you have a link on the whole project? – khmarbaise Jun 06 '18 at 16:00
  • 1
    I looked in the `package.jar` and that just contains the server, no classes. Here is the project: https://github.com/OpenLiberty/draft-guide-arquillian-managed/tree/master/finish. I worked around the issue by adding the `additionalClasspathElements` config to the Failsafe plugin, but you should be able to replicate the issue if you remove that block. – Charles Jun 06 '18 at 16:04
  • The liberty-maven-plugin creates the `package.jar` which is if I correctly understand the wrong..I assume the liberty-maven-plugin should be configured differently...But I'm not sure cause I don't know liberty-maven-plugin... – khmarbaise Jun 06 '18 at 16:15

0 Answers0