首页 > 解决方案 > 分析依赖作为pom的依赖

问题描述

假设我们创建了一个项目,它是一种库项目(项目聚合依赖项)。


    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.packt</groupId>
      <artifactId>axis2-client</artifactId>
      <version>1.0.0</version>
      <packaging>pom</packaging>
      <dependencies>
        <dependency>
          <groupId>org.apache.axis2</groupId>
          <artifactId>axis2-kernel</artifactId>
          <version>1.6.2</version>
        </dependency>
        <dependency>
          <groupId>org.apache.axis2</groupId>
          <artifactId>axis2-adb</artifactId>
          <version>1.6.2</version>
        </dependency>
        <dependency>
          <groupId>org.apache.axis2</groupId>
          <artifactId>axis2-transport-http</artifactId>
          <version>1.6.2</version>
        </dependency>
        <dependency>
          <groupId>org.apache.axis2</groupId>
          <artifactId>axis2-transport-local</artifactId>
          <version>1.6.2</version>
        </dependency>
        <dependency>
          <groupId>org.apache.axis2</groupId>
          <artifactId>axis2-xmlbeans</artifactId>
          <version>1.6.2</version>
        </dependency>
      </dependencies>
    </project>

另一个项目正在使用库项目作为依赖项。


    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.packt</groupId>
      <artifactId>my-axis2-client</artifactId>
      <version>1.0.0</version>

      <dependencies>
        <dependency>
          <groupId>com.packt</groupId>
          <artifactId>axis2-client</artifactId>
          <version>1.0.0</version>
          <type>pom<type>
        </dependency>
      </dependencies>
    </project>

我认为这个用例假设my-axis2-client使用 axis2-client 中的依赖作为直接依赖项。所以这意味着我可以在 my-axis2-client 中使用 org.apache.axis2.client.ServiceClient(in axis2-kernel-1.6.2.jar) 类。但是,当我运行时mvn dependency:anlyze,它会生成以下结果。


    [WARNING] Used undeclared dependencies found:
    [WARNING]     org.apache.axis2:axis2-kernal:jar:1.6.2:compile
    [WARNING] Unused declared dependencies found:
    [WARNING]     compackt:axis2-client:pom:1.0.0:compile

我不认为这是一个有效的警告。请让我知道是否有任何方法可以分析这种情况下的依赖关系。

标签: mavendependenciespom.xml

解决方案


在您的构造中,生成的依赖项是传递的,而不是直接的。你依赖于一个 POM,它本身依赖于 jars。


推荐阅读