4

When I build a project with Maven, dependencies with scope test seems to be out of scope during the integration-test phase. Is this by design, or is there anything I can do to have dependencies with scope test to be included during the integration-test phase?

One answer here on SO suggests that test dependencies are in scope during the integration-test phase, but the answer is just a statement with no references. However, this does not appear to be how Maven works for me.

When I change a given dependency's scope from test to compile, the given dependency is (as expected) available during the integration-test phase.

Should the test scope apply to the integration-test phase, or will I have to set dependency scope to compile in order for them to be available during the integration-test phase?

This is the relevant part of the POM file. What I'm doing is that I attempt to start an instance of a MockServer during the integration test phase. However, it fails as the com.company.msd dependency not is included.

<dependencies>                      
    <dependency>
        <groupId>com.company.msd</groupId>
        <artifactId>MockServerDemo</artifactId>
        <version>0.0.4</version>
        <scope>test</scope>
    </dependency>         
</dependencies>

[...]

<plugin>
  <groupId>org.mock-server</groupId>
  <artifactId>mockserver-maven-plugin</artifactId>
  <version>3.9.17</version>
  <configuration>
    <serverPort>1080</serverPort>
    <proxyPort>1081</proxyPort>
    <logLevel>DEBUG</logLevel
    <initializationClass>com.company.msd.server.DefaultExpectationInitializer</initializationClass>
  </configuration>
  <executions>
    <execution>
      <id>pre-integration-test</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>start</goal>
        </goals>
        </execution>
      <execution>
      <id>post-integration-test</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Note! If I add the dependency as a plugin dependency, it works. However, I'm still curious if Maven by design not includes test scoped dependencies in the integration-test phase.

Community
  • 1
  • 1
sbrattla
  • 5,274
  • 3
  • 39
  • 63
  • Please a post a POM that reproduces the problem. – Tunaki Oct 16 '15 at 08:00
  • @Tunaki question updated with relevant sections of the POM – sbrattla Oct 16 '15 at 08:06
  • In your POM, there are 2 bound phases - `pre-integration-test` and `post-integration-test`. These two obviously are not `integration-test`, so it is clear that maven does not use `test` scope for both of them. Nevertheless, I've never seen phase-scope mapping in maven documentation. I've done some tests, and came to conclusion - maven uses only `compile` scope for `pre-integration-test` phase – Eugene Mar 05 '16 at 14:12

1 Answers1

2

According to maven-failsafe-plugin's integration-test mojo documentaion (link) and source code (link) it does require resolution of dependencies in test scope. In other words, it's not the phase that determines which dependency scope is used but the actually employed mojo.

In your case mockserver-maven-plugin's start mojo does indeed only require resolution of dependencies in compile+runtime scope (link), whereas stop mojo requires the default runtime resolution scope (link). See requiresDependencyResolution descriptor in Maven Mojo API documentation (link) for further details.

If you get similar problems in the future, I suggest that you print out effective pom to understand how Maven interprets your configuration, or otherwise run Maven with -X flag so that you can see the actual class path for each mojo. Maven documentation may be ambiguous at times, but this way you can at least be sure how Maven works in practice.

mkalkov
  • 1,364
  • 1
  • 11
  • 12