Search code examples
javaspring-bootmaven-3

How to refer to another Spring based project using local Maven repository?


There are two projects. Exporting (which exports some functionality), and the Importing (using the aforementioned exporting functionality).

mvn clean install from the exporting project and then adding that project as a dependancy in the importing project should theoretically make the functionality available to the second.

But when it comes to Spring Boot projects, this seem to not work.

In the screenshot below, the 1 refer to how the import works fine, as the local library is found by Maven. However, when you try to refer to the package, it doesn't quite work straight out as it should.

Any tips?

Two projects are on GitHub: https://github.com/madukan/SpringMavenLocalRepoExample

enter image description here


Solution

  • You need to configure spring-boot-maven-plugin, by default it is configured to produce executable jars which are "applications", however you need a "library", something like following should help:

    <build>
        <plugins>
    ...
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <!-- custom classifier for executable jars -->
                            <classifier>exec</classifier>
                            <mainClass>${start-class}</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    ...
        </plugins>
    </build>
    

    Please note, after that executable jar name will be something like xxxx-exec.jar

    Another, actually more preferable, option is to split your project into two submodules: "library" and "application"