依赖分析警告构建失败

通过将dependency:analyze-only目标绑定到生命周期,可以在构建过程中分析项目的依赖关系。默认情况下,分析将在验证生命周期阶段执行。然后,可以通过设置failOnWarning参数将插件配置为在遇到任何依赖项分析警告时使构建失败。有关示例,请参见以下 POM 配置:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>analyze</id>
            <goals>
              <goal>analyze-only</goal>
            </goals>
            <configuration>
              <failOnWarning>true</failOnWarning>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

请注意,dependency:analyze-only目标优先于dependency:analyze使用,因为它不会强制对项目进行进一步编译,而是使用生命周期中早期测试编译阶段生成的编译类。

The project's dependencies will then be automatically analyzed during the verify lifecycle phase, which can be executed explicitly as follows:

mvn verify