从命令行覆盖运行时使用的依赖项版本 [英] Override the dependency version used at runtime from command-line

查看:123
本文介绍了从命令行覆盖运行时使用的依赖项版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

常规:我需要从命令行执行具有覆盖的依赖版本(插件依赖)的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

但是我需要使用最新的此处.

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>

命令行:

?

推荐答案

最佳做法是创建

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.

这篇关于从命令行覆盖运行时使用的依赖项版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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