0

I have created a spring boot project (Project A) and I have run the build as maven install. This has created an executable jar file in the .m2 folder.

I want to use the above project as a dependency in two other spring boot projects(Project B and Project C). I have added the dependency of the project A in pom.xml of project B. But the dependency is being included as a folder under Maven Dependencies. I am only able to import required classes from project A, if project A is open in local project explorer. If I close Project A, the dependencies are not being resolved and it is throwing an error.

Am I doing something wrong while building the first project (A). Below is the build tag in pom.xml for project A. Can we add an executable file as a dependency?

<build>
    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
            <includes>
                <include>**</include>
            </includes>
        </resource>
    </resources>
    <finalName>${project.artifactId}-${project.version}${build.number}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Please help me understand if there is something wrong here. Thanks in Advance :)

codegeek
  • 11
  • 5

1 Answers1

0

By default each Spring Boot application is inherited from Spring Boot's artifact so loads lot of dependent libraries automatically via maven's 'dependencyManagement' feature. Also due to same reason - not all required libraries will be automatically resolved as dependencies when Spring Boot application is turned into shared library.

To solve this, you need extract shared classes into dedicated shared library and use this library as dependency between projects. No simple way, sorry.

Alex Chernyshev
  • 1,719
  • 9
  • 11