I have a multi module maven spring-booot maven project. One of the child modules is a stub(a spring boot app) that I want to start and then stop during integration tests of myRealApp.
Parent Pom
|
|----myRealApp module(spring boot app)
|----stub-of-some-remote-rest-api module(This is also a spring-boot app)
This is how the pom file looks like in the module myRealApp. Which also has all the integration tests. Its trying to start the stub module during before integration-tests phase. But I get the error when I run maven goal in the child module directory:
mvn integration-tests -X
Error: Could not find or load main class io.swagger.MyStub
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:run (start-boot) on project: Could not exec java
I can see in debug mode that that the working directory is set correctly.
Pom of myRealApp:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
<executions>
<execution>
<configuration>
<workingDirectory>${project.parent.basedir}/module-of-my-stub/src/main/java</workingDirectory>
<mainClass>io.swagger.MyStub</mainClass>
</configuration>
<id>start-boot</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-boot</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
Maybe I am not allowed to set workingDirectory in individual executions, or give reference to an other module?
The stub is there acting like a remote rest service which my application is depending on, which I used during development since the actual remote service's test environment was not reliable and was down half of the time. So decided to also use it in Integration tests too.
/my-stub/src/main/java
? Please follow conventions for Maven and the conventions for Spring Boot....Furthermore you should read the guides about testing spring boot apps cause there is no need to write a stub for spring boot apps... – khmarbaisemodule-of-my-stub
dependency to the classpath thespring-boot-maven-plugin:run
goal uses. It doesn't look like there is a direct way, though there is a useTestClasspath option. This link also discusses an alternative approach. – df778899module-of-my-stub
tomyRealApp
, and then addinguseTestClasspath
to the existingspring-boot-maven-plugin:run
configuration, this would makeMyStub
visible to it on the classpath. Otherwise, theclassesDirectory
trick in the link above should be able to point it to thetarget/classes
directory undermodule-of-my-stub
. – df778899