【发布时间】:2017-04-12 08:30:37
【问题描述】:
我有一个多模块的 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>
模块 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>
模块 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>
,Module B 不能再解析Module A 的依赖,会看到'package doesn't exist'、'cannot find symbol'等信息,表示看不到Module A 的class。
这是一个错误吗?谁能帮我解决这个问题?
【问题讨论】:
-
希望这个post可以帮助你。
-
绝对有帮助。非常感谢。如果您将其作为答案提交,我会批准。
-
当然。不客气。
-
添加了答案。
标签: spring maven spring-boot