Maven 模块看不到可靠的子模块
Maven module doesn't see dependable submodule
我有以下项目结构:
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
我该如何解决这个问题?
module1
对 shared
的依赖类型为 pom
...
<dependency>
<groupId>shared</groupId>
<artifactId>shared</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
这意味着 module1
将继承 shared
的依赖项,但它无法访问 shared
.
中的任何 类
通常 <type>pom</type>
与 <scope>import</scope>
相关联,因为这会在 module1
中包含 shared
的任何依赖项。在你的情况下,你想要更多 shared
的传递提供的依赖项,你也想要 shared
的 类,所以删除 ...
<type>pom</type>
... 这将导致依赖项使用默认类型 (jar),然后允许 module1
依赖于 (a) shared
的依赖项和 (b) shared
的 类.
我有以下项目结构:
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
我该如何解决这个问题?
module1
对 shared
的依赖类型为 pom
...
<dependency>
<groupId>shared</groupId>
<artifactId>shared</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
这意味着 module1
将继承 shared
的依赖项,但它无法访问 shared
.
通常 <type>pom</type>
与 <scope>import</scope>
相关联,因为这会在 module1
中包含 shared
的任何依赖项。在你的情况下,你想要更多 shared
的传递提供的依赖项,你也想要 shared
的 类,所以删除 ...
<type>pom</type>
... 这将导致依赖项使用默认类型 (jar),然后允许 module1
依赖于 (a) shared
的依赖项和 (b) shared
的 类.