【发布时间】:2018-07-09 11:43:49
【问题描述】:
我有以下项目结构:
Root:
module_1
module_2
shared
module_1 依赖于共享模块。
因此 Root pom.xml 看起来像这样:
<groupId>root</groupId>
<artifactId>root</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>root</name>
<modules>
<module>module_1</module>
<module>module_2</module>
<module>shared</module>
</modules>
module_1 pom.xml:
<parent>
<groupId>root</groupId>
<artifactId>root</artifactId>
<version>0.0.1</version>
</parent>
...
<dependencies>
<dependency>
<groupId>shared</groupId>
<artifactId>shared</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
</dependencies>
共享 pom.xml
<parent>
<groupId>root</groupId>
<artifactId>root</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>shared</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>shared</name>
<description>shared</description>
但是当我尝试构建根项目时,maven 输出编译错误,module_1 看不到来自共享模块的类:
[ERROR] Some_class_from module_1 cannot find symbol
[ERROR] symbol: Some_class_from_shared_module
我该如何解决这个问题?
【问题讨论】:
-
共享 pom.xml 中的打包应该是 jar(而不是 pom)。
-
首先将共享项目做成一个jar包而不是pom...否则依赖它没有意义...
标签: java maven dependencies multi-module