Chris Brown
Chris Brown

Reputation: 71

cannot find symbol of spring boot class when using repackage of spring-boot-maven-plugin

I created a simple project to showcase my problem: https://github.com/sentinel0815/testing-spring-boot-app

This is a maven multi module project (reactor) having only

The folder structure is like this:

   testing-spring-boot-app (root/parent maven module)
   |- my-project-application (maven module)
   | \- src/main/java/org/myproject/MyProjectApplication.java
   \- my-project-integrationtest (maven module)
     \- src/test/java/org/myproject/MyProjectFacadeIntegrationTest.java

The my-project-integrationtest module has a dependency to the my-project-application module. The integration test class MyProjectFacadeIntegrationTest should start a spring boot application using the spring boot application class MyProjectApplication from the my-project-application module.

I can execute the test in the IDE successfully. During maven build there is a failure "cannot find symbol" saying that the application class MyProjectApplication is not know in test class MyProjectFacadeIntegrationTest ("cannot find symbol").

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/tmp/testing-spring-boot-app/my-project-integrationtest/src/test/java/org/myproject/MyProjectFacadeIntegrationTest.java:[7,40] cannot find symbol
  symbol:   class MyProjectApplication
  location: package org.myproject
[INFO] 1 error
[INFO] -------------------------------------------------------------

It has to do something with the spring-boot-maven-plugin which we must use in our real application. If I comment out the 'repackage' goal in the plugin configuration in the my-project-application/pom.xml the maven build works fine.

Can anyone explain this? What is going on in the repackage goal of this plugin? Is the this behavior as expected? Is there any solution/ workaround to get my test running?

PS: Of course, I could create the spring boot test inside the application maven module and everything would work. But my real project is much bigger with a lot of more maven modules and in one of them it is appropriated to create the spring boot app there (which should have all the dependencies of the real application etc.) So please do not suggest to move the test class into the application maven module ;-)

Upvotes: 0

Views: 160

Answers (1)

Arun Duraisamy
Arun Duraisamy

Reputation: 81

@Chris Brown please refer the link to add a dependency to a Spring Boot Jar in another project

To fix the issue update the following.

In my-project-application pom.xml add classifier

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring.boot.version}</version>
            <executions>
                <execution>
                    <id>repackage</id>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                         <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

In my-project-integrationtest pom.xml add the version and scope

<dependency>
    <groupId>foo.bar</groupId>
    <artifactId>my-project-application</artifactId>
    <version>0.1.0-SNAPSHOT</version>
     <scope>test</scope>
</dependency> 

Upvotes: 0

Related Questions