在Maven子pom中防止覆盖依赖版本 [英] Preventing overriding dependency version in Maven child pom

查看:86
本文介绍了在Maven子pom中防止覆盖依赖版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在父pom中有一个dependencyManagement部分,例如

I have a dependencyManagement section in parent pom like

<dependencyManagement>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.1</version>
    </dependency>
</dependencyManagement>

和一个孩子pom,有它

and a child pom, having it

<dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>

我尝试使用 enforcer插件,仅允许在父级中设置,但不能设置.我想让构建失败.可以通过该插件或其他方式实现吗?

I've tried to prevent this kind of overriding in child poms using enforcer plugin, allowing these only to be set in parent, but haven't been able to. I'd like this to fail the build. Is that possible, with that plugin or some other way?

DependencyCovergence ,它会强制所有版本相同,但这太严格了,因为我不想控制所有的传递性依赖关系-只是明确定义的依赖项.

There is DependencyCovergence, which forces all versions to be the same, but that's too restrictive as I don't want to control all transitive dependencies - just the ones defined explicitly.

如果我可以防止在子pom中引入任何新的依赖关系,我会很高兴-定义的所有内容都应该真正在父pom中定义,然后在子pom中进行提及(如果需要的话).

I'd be happy if I could just prevent introducing any new dependencies at all in child poms - everything defined should really be defined in the parent pom, and then just mentioned, if needed, in the child.

推荐答案

您可以添加

You could add a dependency:analyze-dep-mgt execution in your parent pom and configure it to fail on version mismatches:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>analyze</id>
            <phase>package</phase>
            <goals>
              <goal>analyze-dep-mgt</goal>
            </goals>
            <configuration>
              <failBuild>true</failBuild>
              <ignoreDirect>false</ignoreDirect>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

这篇关于在Maven子pom中防止覆盖依赖版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆