Hi, I am stuck at a point right now, where I need to startup a complex spring boot application, including its test classpath on the testing machine. I am using maven for the build, and the spring boot plugin for repacking it into a single jar, and before that for executing the integrations tests. We have some processes however (recreation of DB, populate with test data,..), that will need to have the test classpath included in the running application after the tests and its deployment in a docker on a test system.

I saw that the plugin supports including test classpath for the goals run and start. But sadly not for repackage. I failed including them manually but I really don't want to give up using the boot plugin!

I tried using the Attribute:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    [...]
    <includes>
        <include>
            <groupId>groupID</groupId>
            <artifactId>artifactID</artifactId>
            <classifier>tests</classifier>
        </include>
    </includes>
    [...]

in combination with the maven-jar plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

... but using this leads to having ONLY the included artifacts and no others any more.

I would be very happy if you would include this feature also for the repackage goal or have any hint for me how I could achieve that.

Many Thanks, Simon

Comment From: snicoll

Usually the integration tests are running against a packaged/deployed application but the application itself does not need test-scoped dependencies. Your setup seems a bit unusual: if you need those dependencies in the target application, don't mark them as test only. You could, for instance, use a Maven profile to add them with the regular scope so that they don't get added in other scenario.

Does that help?

Comment From: slandes

Hi Stephane, many thanks for your reply. I did add the test-jars in an additional "test-jar" profile as dependencies and it does work. However, first I need to mvn install in order to install the test-jars in the local repo. Then I am able to execute mvn again for the repackage in the special profile ... this way mvn can access the test-jar from the module itself. Many Thanks. Best Regards, Simon

Comment From: snicoll

I am not sure I understand why you had to do this but that's more of a Maven question than a Spring Boot question. Thanks for the feedback.

Comment From: suryajit7

This is actually needed. We generally used to have a project that needed only the main folder in classpath which can be deployed without tests. But increasingly, we can see many projects trying to package their project along with their tests so that they can be run along with the tests. Also, my many testing projects (like mine) require test folder to be included within the package so that the tests inside the test folders can be run. The main folder contains the test framework and the test folder contains the test utilizing the classes from main. I would request this option to be made available within the plugin. thanks!

Comment From: wilkinsona

@suryajit7 I'm afraid our position on this hasn't changed and packaging tests and their dependencies in the uber jar isn't something that we want to support directly. It may already be achievable using an approach such as this one. You may also be interested in https://github.com/spring-projects/spring-boot/issues/36115 which is in a somewhat related area.