我使用maven-enforcer-plugin来检查依赖性收敛问题.典型的输出是:
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.DependencyConvergence failed
with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for junit:junit:3.8.1 paths to dependency are:
+-foo:bar:1.0-SNAPSHOT
+-ca.juliusdavies:not-yet-commons-ssl:0.3.9
+-commons-httpclient:commons-httpclient:3.0
+-junit:junit:3.8.1
and
+-foo:bar:1.0-SNAPSHOT
+-junit:junit:4.11
]
Run Code Online (Sandbox Code Playgroud)
看到这条消息,我通常会通过排除传递依赖来"解决"它,例如
<dependency>
<groupId>ca.juliusdavies</groupId>
<artifactId>not-yet-commons-ssl</artifactId>
<version>0.3.9</version>
<exclusions>
<!-- This artifact links to another artifact which stupidly includes
junit in compile scope -->
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我想了解这是否真的是一个解决方案以及以这种方式排除库的风险.照我看来:
如果我选择使用较新版本,"修复"通常是安全的.这依赖于库作者保持向后兼容性.
通常对Maven构建没有影响(因为更接近的定义获胜),但是通过排除依赖性我告诉Maven我知道这个问题并因此安抚maven-enforcer-plugin.
我的想法是否正确,是否有另一种处理此问题的方法?我对那些关注一般情况的答案感兴趣 - 我意识到junit上面的例子有点奇怪.
所以,我正在尝试使用最新版本的一些插件.之前我已经使用了先决条件标签,但是很多资源(例子)说它应该被认为是弃用的,而且应该使用maven-enforcer-plugin.这是我的配置:
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-maven-3</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.0.4</version>
</requireMavenVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,当我运行mvn版本时:display-plugin-updates我仍然得到这个文本:
[ERROR] Project does not define required minimum version of Maven.
[ERROR] Update the pom.xml to contain
[ERROR] <prerequisites>
[ERROR] <maven>3.0</maven>
[ERROR] </prerequisites>
[INFO]
[INFO] Require Maven 2.0.6 to use the following plugin updates:
[INFO] maven-jar-plugin ................................................ 2.4
[INFO] maven-shade-plugin ............................................ 1.7.1
[INFO]
[INFO] Require Maven 2.2.1 to use the following plugin updates: …Run Code Online (Sandbox Code Playgroud) 我正在尝试为maven设置enforcer插件以强制执行最低Java版本.但是,每当我试图跑步时mvn enforcer:enforce,我得到:
目标org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce的参数'rules'缺失或无效
这是我的pom文件的相关部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-java</id>
<phase>validate</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>(1.7.0-20,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我也试过更换<requireJavaVersion>块<alwaysPass/>,以防万一无效,但它仍然失败并出现同样的错误.
我想使用maven enforcer插件检查我的路径上是否有重复的类.我从这里试过这个例子.
但当我这样运行时:
mvn enforcer:enforce
我明白了:
无法在项目datapopulator上执行目标org.apache.maven.plugins:maven-enforcer-plugin:1.0.1:enforce(default-cli):目标org.apache.maven.plugins的参数'rules':maven-enforcer -plugin:1.0.1:强制执行缺失或无效
有没有办法正确使用它?
编辑#1
如果将我的配置更改为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysPass />
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
产生相同的错误.
我想在Maven项目上强制执行Maven Enforcer插件的requireReleaseDeps规则,而不需要任何POM配置作为命令行调用.
根据文档,我应该能够像这样传递规则参数
mvn enforcer:enforce -Drules=requireReleaseDeps
Run Code Online (Sandbox Code Playgroud)
或许这应该有效
mvn enforcer:enforce -Drules=org.apache.maven.plugins.enforcer.RequireReleaseDeps
Run Code Online (Sandbox Code Playgroud)
但是这两个调用都会产生
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce (default-cli) on project hel
lo-world: The parameters 'rules' for goal org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce are missing or in
valid -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
任何人都知道这种使用场景是否真的以某种方式工作,还是我必须在这个阶段深入调试插件来解决这个问题?
我enforcer在根 pom 的多节点项目中使用插件,但我有一个测试模块,我真的不关心在那里运行插件,因为它不会创建任何 jar 并且仅用于测试 propuse。有没有办法跳过插件配置中的模块之一?
检查文档我找不到任何东西。只有如何禁止某些特定的依赖项。https://maven.apache.org/enforcer/enforcer-rules/bannedDependencies.html
将插件放在每个子模块中的解决方案是可能的,但它很危险,因为如果我创建一个新的子模块,我可能会忘记在那里添加它
这是我的插件配置。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-maven-version-and-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.3.9</version>
</requireMavenVersion>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
</bannedDependencies>
<dependencyConvergence></dependencyConvergence>
</rules>
</configuration>
</execution>
</executions>
<configuration>
<fail>true</fail>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我正在Eclipse中使用maven项目为sonarqube创建一个新的语言插件,并在构建项目时面临以下错误:
Failed to execute goal com.mycila.maven-license-plugin:maven-license-plugin:1.9.0:
check (enforce-license-headers) on project sonar-java-plugin:
Some files do not have the expected license header -> [Help 1]
Run Code Online (Sandbox Code Playgroud) 以下是我看到的错误,让我困惑的是为什么它会依赖于 2 个版本的 my-engine 依赖项。一个是 0.9.0-20180510.015454-2,另一个是 0.9.0-SNAPSHOT。
这是我使用的命令:
mvn clean install -DskipTests
Run Code Online (Sandbox Code Playgroud)
在 pom.xml 中,我将版本指定为 ${project.version},这里应该是 0.9.0-SNAPSHOT。你能帮我吗?谢谢
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce) @ zeppelin-server ---
[WARNING]
Dependency convergence error for org.apache.hadoop:hadoop-client:2.7.3 paths to dependency are:
+-myproject:my-server:0.9.0-SNAPSHOT
+-myproject:my-engine:0.9.0-20180510.015454-2
+-org.apache.hadoop:hadoop-client:2.7.3
and
+-myproject:my-server:0.9.0-SNAPSHOT
+-myproject:my-engine:0.9.0-SNAPSHOT
+-org.apache.hadoop:hadoop-client:2.7.5
Run Code Online (Sandbox Code Playgroud)
这是 pom.xml 中的依赖项
<dependency>
<groupId>myproject</groupId>
<artifactId>my-zengine</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>my-zengine</artifactId>
<version>${project.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我在执行时遇到以下错误mvn versions:display-plugin-updates。基于此讨论,这已在 2.6 中修复,但我使用的是 2.7(尝试使用 2.6 但没有成功)。
[ERROR] Project does not define required minimum version of Maven.
[ERROR] Update the pom.xml to contain maven-enforcer-plugin to
[ERROR] force the Maven version which is needed to build this project.
[ERROR] See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[ERROR] Using the minimum version of Maven: 3.0.5
Run Code Online (Sandbox Code Playgroud)
这是我的<pluginManager>插件:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.5.4</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId> …Run Code Online (Sandbox Code Playgroud) 在/sf/answers/4157299891/之后,现在可以从命令行调用 Maven 执行器插件。
这很有效,但不幸的是我还不明白是否可以通过命令行设置规则参数。一个例子是version在RequireMavenVersion规则中。