传递依赖关系不可见?

时间:2018-03-18 07:29:55

标签: maven pom.xml transitive-dependency

customModule取决于user-portal应用。 user-portal取决于util模块

以下是相关的POM

customModule POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
        <artifactId>parent-build</artifactId>
        <groupId>com.myComp.user</groupId>
        <version>1</version>
        <relativePath>../../pom.xml</relativePath>
</parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>customModule</groupId>
  <artifactId>dbunit</artifactId>
  <dependencies>
    <dependency>
        <groupId>com.myComp.user</groupId>
        <artifactId>user-portal</artifactId>
        <version>1.15</version>
        <scope>compile</scope>
        <type>war</type>
    </dependency>
  </dependencies>
</project>

user-portal POM以utils为依赖

 <dependencies>
    <dependency>
        <groupId>com.myComp.user.utils</groupId>
        <artifactId>utils</artifactId>
        <version>1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
 </dependencies>

utils下的customModule类不可见。我不确定为什么传递依赖/类在这里不可见?

1 个答案:

答案 0 :(得分:1)

当依赖战争包装时,战争中的类别是不可见的。您应该将<attachClasses>true</attachClasses>添加到user-portal项目中的war插件中。这将产生战争和类的罐子。
在依赖项目中,您应该依赖于<classifier>classes</classifier>而不是战争。

在user-portal pom.xml中

 <build>
    ...
      <plugins>
      ...
         <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.0</version>
          <configuration>
            <attachClasses>true</attachClasses>
          </configuration>
        </plugin>
      ...
      </plugins>
    ...
    </build>

customModule pom.xml

   <dependency>
        <groupId>com.myComp.user</groupId>
        <artifactId>user-portal</artifactId>
        <version>1.15</version>
        <classifier>classes</classifier>
    </dependency>

作为旁注,默认范围是编译,您不必指定它。

来源= https://pragmaticintegrator.wordpress.com/2010/10/22/using-a-war-module-as-dependency-in-maven/

相关问题