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-tes
t 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With