2

I have the following directory structure:

src
|
|___ main
|
|___ test
      |
      |___resources

I want to include all the files from test resources in the classpath when running the start goal (spring-boot:start, different than spring-boot:run) in phase pre-integration-test.

My pom.xml is:

            <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>
                        <wait>1000</wait>
                        <maxAttempts>30</maxAttempts>
                    </configuration>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I tried without success including flags addResources or useTestClasspath, I really can't figure out how they are supposed to work even reading the documentation (https://docs.spring.io/spring-boot/docs/current/maven-plugin/start-mojo.html).

Thanks in advance.

italktothewind
  • 1,950
  • 2
  • 28
  • 55
  • Isn't it a better idea to using Maven profiles and create a test profile? I think that's the way how this should be done with Maven. – Jasper Huzen Jan 24 '20 at 11:29

1 Answers1

0

Here is a working Maven configuration:

<plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.2.2.RELEASE</version>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
            <execution>
                <id>pre-integration-test</id>
                <goals>
                    <goal>start</goal>
                </goals>
                <configuration>
                    <classesDirectory>${project.build.testOutputDirectory}:${project.build.outputDirectory}</classesDirectory>
                    <wait>1000</wait>
                    <maxAttempts>30</maxAttempts>
                </configuration>
            </execution>
            <execution>
                <id>post-integration-test</id>
                <goals>
                    <goal>stop</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
Javide
  • 2,477
  • 5
  • 45
  • 61