Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot application as dependency

My problem is that I have a multi module maven build where one part is generated by swagger as a spring boot application. The second module should extend on the code generated and finally started. When I compile with maven the second project does not find the classes in the generated code. I checked the jar and the class files end up in a BOOT-INF directory when building the jar. I suspect that this is the problem. What is the best solution to compile my code.

the parent pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.xxx</groupId>
    <artifactId>applications</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
</parent>

<name>project1-connector</name>
<artifactId>project1-connector</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<scm>
    <developerConnection>scm:git:ssh://[email protected]:7999/bla/project1-java-repo.git</developerConnection>
</scm>

<properties>
    <majorVersion>1</majorVersion>
    <minorVersion>0</minorVersion>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
                        <language>spring</language>
                        <configurationFile>${project.basedir}/src/main/resources/apiConfig.json</configurationFile>
                        <output>${project.basedir}/project1-api</output>
                        <configOptions>
                            <sourceFolder>src/main/java</sourceFolder>
                        </configOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<modules>
    <module>project1-api</module>
    <module>project1-backend</module>
</modules>

project1-api generated pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xxx</groupId>
    <artifactId>project1-api</artifactId>
    <packaging>jar</packaging>
    <name>project1-api</name>
    <version>1.0.1</version>
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <springfox-version>2.7.0</springfox-version>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <!--SpringFox dependencies -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox-version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox-version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>
    <!-- Bean Validation API support -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
        </dependency>
    </dependencies>
</project>

project1-backend pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.xxx</groupId>
<artifactId>project1-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>project1-backend</name>
<description>Project1 Connection</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>9</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.batch</groupId>
        <artifactId>spring-batch-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.xxx</groupId>
        <artifactId>project1-api</artifactId>
        <version>1.0.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

like image 830
Xtroce Avatar asked Apr 26 '18 11:04

Xtroce


People also ask

What is the main dependency of a spring boot application?

Working of Dependency Management in Spring-Boot Dependency is nothing but a 'Library' that provides specific functionality that we can use in our application. In Spring-Boot, Dependency Management and Auto-Configuration work simultaneously.

How does spring boot handle dependencies?

Dependency management is very easy in Spring boot because of its auto-configuration, it manages every configuration for us, we do not need to worry about the version of the dependency. Dependency is nothing but a library that provides specific support to the application to run and implement.

How can I see spring boot dependencies?

The list of dependencies is available in the Appendix F. of the documentation and in the pom. xml of the spring-boot-dependencies artifact, which you should be able to find on your classpath. You can also go the public repository of Spring Boot and see the pom.


1 Answers

As stated here:

https://happilyblogging.wordpress.com/2017/07/31/using-spring-boot-application-as-dependency-in-another-spring-boot-application-project/

The problem is in the generated pom.xml.

If I add the configuration part to the project1-api spring-boot plugin part, it works.

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </execution>
        </executions>
    </plugin>
like image 115
Xtroce Avatar answered Oct 05 '22 07:10

Xtroce