Linux 拨号vps windows公众号手机端

maven怎么排除父类依赖

lewis 8年前 (2017-10-27) 阅读数 16 #程序编程
文章标签 maven

在Maven中排除父类依赖可以通过在子项目的pom.xml文件中使用元素来实现。下面是一个示例:

<project>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0.0</version>
  </parent>
  
  <groupId>com.example</groupId>
  <artifactId>child-project</artifactId>
  <version>1.0.0</version>
  
  <dependencies>
    <!-- 子项目依赖 -->
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>dependency1</artifactId>
      <version>1.0.0</version>
    </dependency>
    
    <!-- 父项目依赖 -->
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>dependency2</artifactId>
      <version>1.0.0</version>
      <exclusions>
        <exclusion>
          <groupId>com.example</groupId>
          <artifactId>dependency3</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>

在上面的例子中,子项目child-project排除了父项目parent-project的一个依赖dependency3,通过在dependency2<exclusions>元素中指定要排除的依赖的<groupId><artifactId>

这样,在构建子项目时,Maven就会忽略该父类依赖的传递性依赖。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门