问题描述
常规:我需要从命令行执行具有覆盖的依赖版本(插件依赖)的Maven插件.插件将不会在项目pom中定义.
General: I need execute maven plugin from command line with overridden dependency version (plugin dependency). Plugin will not be defined in project pom.
具体:我需要执行 maven-checkstyle-plugin
作为团队建设的步骤;此插件将不会被定义为项目pom.我使用以下命令行:
Concrete: I need to execute maven-checkstyle-plugin
as step in teamcity build; this plugin will not be defined project pom. I use following command-line:
mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check -Dencoding=UTF-8
但是我需要使用最新的 checkstyle 如此处.
But I need to execute plugin with latest checkstyle as showed here.
POM xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
</plugin>
命令行:
mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
POM xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
</plugin>
命令行:
?
推荐答案
最佳做法是创建使用您的设置的Maven配置文件,然后在CI上构建时激活此配置文件.
The best practice is to create a Maven profile with your settings, then activate this profile when building on CI.
示例个人资料:
<profiles>
<profile>
<id>ci</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
示例如何在TeamCity上启用它:mvn checkstyle:check -Pci
Example how to enable it on TeamCity: mvn checkstyle:check -Pci
通常将execution
部分添加到配置文件配置中,以使插件目标在某个阶段作为正常构建的一部分自动运行,但仅当通过例如mvn install -Pci
启用了ci
配置文件时.
Usually execution
section is added to profile configuration to make the plugin goal run automatically as part of normal build at a certain phase, but only when ci
profile is enabled via, e.g., mvn install -Pci
.
这篇关于从命令行覆盖运行时使用的依赖项版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!