如何在多模块Spring-boot Maven项目中构建特定模块 [英] How to Build specific module in a multi module spring-boot maven project

查看:100
本文介绍了如何在多模块Spring-boot Maven项目中构建特定模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个多模块spring boot maven项目.

I have create a multi module spring boot maven project.

但是当我使用

mvn clean package -pl module2 spring-boot:run

在控制台中.它告诉我,module1中的某些类找不到.

in console. It tell me that some class in module1 can not find.

但是我已经在module2中添加了依赖项. module2是最终项目.

But I have added the dependency in module2. The module2 is the final project.

项目结构如下.

父项目的pom.xml

parent project`s pom.xml

<groupId>com.example</groupId>
<artifactId>multi-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>module1</module>
    <module>module2</module>

</modules>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath/>
</parent>

<properties>
    ...
</properties>

</dependencies>
    ...
<dependencyManagement>
    ...
</dependencyManagement>

module1中的pom:

the pom in module1:

<groupId>com.example</groupId>
<artifactId>module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
    <groupId>com.example</groupId>
    <artifactId>multi-module</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

module2中的pom.xml:

the pom.xml in module2:

<artifactId>personalinfo</artifactId>
<name>personalinfo</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<parent>
    <groupId>com.example</groupId>
    <artifactId>multi-module</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<dependencies>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>module1</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

<build>
    <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>

推荐答案

您需要调整pom.

父pom:

   <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

模块pom(包含您的Main)

Module pom (containing your Main)

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>Your mainClass</mainClass>
                <fork>true</fork>
                <skip>false</skip>
            </configuration>
        </plugin>
    </plugins>
</build>

重视Configuration > skip

这篇关于如何在多模块Spring-boot Maven项目中构建特定模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆