flatten-maven-plugin deploy multi module project

816 views Asked by At

parent project maven

<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<modules>
    <module>module1</module>
    <module>module2</module>
</modules>

<properties>
    <revision>0.1.10-SNAPSHOT</revision>
</properties>

<build>
    <plugins>
        <plugin>
             flatten-maven-plugin
              ...
        </plugin>
    </plugin>
<build>

child 1 module

<parent>
    <artifactId>artifactId</artifactId>
    <groupId>groupId</groupId>
    <version>${revision}</version>
</parent>

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

child 2 module

<parent>
    <artifactId>artifactId</artifactId>
    <groupId>groupId</groupId>
    <version>${revision}</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>module2</artifactId>
<dependencies>
    <dependency>
        <groupId>groupId</groupId>
        <artifactId>module1</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>

module1 is a springboot project which should be packaged to a executable jar, and module2 should be deployed to nexus Now, module2 is uploaded to nexus successfully but module1 unable to start by java -jar

2

There are 2 answers

0
zhuochen shen On BEST ANSWER

add build in module1 can fix the problem

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>{version}</version>
            <configuration>{mainClass}</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
0
P.Sanjay On

When you create a jar for your module, that jar must have all the dependency jar within it. This type of jar is called a Fat jar or executable jar. Add below tag in you pom.xml of module1 which will create and package all the dependency jars within it. Note : I can see that you have already added the "spring-boot-maven-plugin" but you have missed to provide your Spring boot main class and repackage goal.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>{Your spring boot main class}</mainClass>
            </configuration>

            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
           </executions>

        </plugin>
    </plugins>
</build>