Java – how to make Maven build fail on duplicate dependencies?

If I have two identical dependencies in the same POM, I want the build to fail At present, I can use Maven dependency plugin's "analyze duplicate" to detect it However, like others, there is no failonwarning option (in addition, it prints at the info level, not a warning) Is there an alternative extension to this?

Solution

Usually, when you want the build to fail for some reason, you can use a good plug-in to see @ L_ 403_ 0@. This plug - in can configure a set of rules that cannot be built after validation

In this case, it needs to be a rule for checking duplicate dependencies, and there is only one built-in rule: < banduplicatepomdependencyversions > So you can

<plugin>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.4.1</version>
  <executions>
    <execution>
      <id>enforce-no-duplicate-dependencies</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <banDuplicatePomDependencyVersions/>
        </rules>
      </configuration>
    </execution>
  </executions>
</plugin>

Unfortunately, this rule is not documented (however, it will be in the next version, see menforcer-259), but it has existed since plug-in version 1.3 (menforcer-152)

The purpose of this rule is to check that no two duplicate declarations have the same 'dependencies dependency. (groupId:artifactId:type:classifier)’; That is, two declared dependencies with the same group ID and artifact ID declared in POM must have different types and / or classifiers

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>