我已经创建了一个多模块spring启动maven项目。
但当我用
mvn clean package -pl module2 spring-boot:run在控制台里。它告诉我module1中的某个类找不到。
但是我在module2中添加了依赖项。module2是最后一个项目。
项目结构如下。
父项目的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:
<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>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>发布于 2018-04-08 17:38:57
你需要调整你的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 (包含主模块)
<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
发布于 2019-04-18 17:15:08
@位扫描字节的回答是正确的,但可以简化配置:
亲本pom
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>模块pom ( @SpringBootApplication所在的模块)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>在这里可以找到一个简单的演示项目:https://github.com/drahkrub/spring-boot-multi-module
https://stackoverflow.com/questions/49715215
复制相似问题