我有一个多模块 Maven 设置。一个父模块,加上两个子模块(子模块)A 和 B。模块 B 依赖于 A。但是,如果我在模块 A 中使用 spring-boot-maven-plugin,则编译依赖关系不会得到解决,模块 B 的编译目标将抛出“找不到符号”和“包不存在”错误。如果我不使用该插件,一切都会正常,但是我将无法在该项目中删除它。
这是重现该问题的方法:
父pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.whatever</groupId>
<artifactId>theparent</artifactId>
<version>2.7.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>service</module>
<module>serviceClient</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
Module A
<modelVersion>4.0.0</modelVersion>
<artifactId>service</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.whatever</groupId>
<artifactId>theparent</artifactId>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
Module B
<modelVersion>4.0.0</modelVersion>
<artifactId>serviceClient</artifactId>
<parent>
<groupId>com.whatever</groupId>
<artifactId>theparent</artifactId>
<version>2.7.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.whatever</groupId>
<artifactId>service</artifactId>
<version>2.7.0-SNAPSHOT</version>
</dependency>
</dependencies>
现在,您所要做的就是在模块 A 中有一个类,在模块 B 中有另一个类,该类导入并使用第一个类。通过在父模块级别运行“mvn clean install”完成此操作后,它应该可以正常编译。但是,一旦将此插件添加到模块 A 中:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.whatever.Application</mainClass>
</configuration>
</plugin>
</plugins>
</build>
,模块 B 无法再解析来自模块 A 的依赖关系,并且您将看到“包不存在”、“找不到符号”等消息,表明它无法看到来自模块 A 的类。
这是一个错误吗?谁能帮我解决这个问题?