繁体   English   中英

Maven模块看不到可靠的子模块

[英]Maven module doesn't see dependable submodule

我有以下项目结构:

Root:  
   module_1   
   module_2  
   shared

module_1取决于共享模块。

因此, 根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

我怎样才能解决这个问题?

module1shared的依赖类型为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>相关联,因为它的作用是包括module1shared任何依赖关系。 在您的情况下,您还需要更多可传递提供的shared依赖关系,您也想要shared的类,因此删除...

<type>pom</type>

...这将导致依赖项使用默认类型(jar),这将允许module1依赖(a) shared的依赖项和(b) shared的类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM