1

我有包含所有项目版本和排除项的父 pom 我想从子项中的父项中获得相同的排除项,我该如何实现。

儿子项目项目继承了他的父亲版本,但需要工件a,我希望他避免使用a,我该怎么做?

我的目标是让字母罐没有依赖

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>parent-pom</artifactId>
  <groupId>parent</groupId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <dependencies>
    <dependency>
        <groupId>com.somthing.ltetters</groupId>
        <artifactId>ltetters</artifactId>
        <version>1.4</version>
        <exclusions>
            <exclusion>
                <groupId>com.somthing.ltetters</groupId>
                <artifactId>a</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  </dependencies>

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>1.0.0</modelVersion>
  <artifactId>son-project</artifactId>
  <packaging>war</packaging>
  <version>3.9.0.SNAPSHOT</version>

  <parent>
    <groupId>parent-pom</groupId>
    <artifactId>parent</artifactId>
    <version>0.1.0</version>
  </parent>
  <dependencies>
    <dependency>
        <groupId>com.somthing.ltetters</groupId>
        <artifactId>ltetters</artifactId>
    </dependency>
  </dependencies>

4

1 回答 1

5

如果您已经在父 pom 中指定了依赖项,它将被所有子工件继承,您不需要再次指定它。如果您实际上不想默认继承它,则改为在父 pom 中使用 < dependencyManagement > ,然后在子项目中指定不带版本或排除的依赖项。因此,您的父 pom 将如下所示:

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>parent-pom</artifactId>
  <groupId>parent</groupId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.somthing.ltetters</groupId>
        <artifactId>ltetters</artifactId>
        <version>1.4</version>
        <exclusions>
            <exclusion>
                <groupId>com.somthing.ltetters</groupId>
                <artifactId>a</artifactId>
            </exclusion>
        </exclusions>
      </dependency>
    </dependencies>
    ...
  <dependencyManagement>
  ...

所有子项目看起来仍然与您的问题相同。

于 2016-01-06T19:34:54.073 回答