Override the dependency version used at runtime from command-line

末鹿安然 提交于 2020-01-15 09:36:47

问题


General: I need execute maven plugin from command line with overridden dependency version (plugin dependency). Plugin will not be defined in project 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>

command-line:

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>

command-line:

?

回答1:


The best practice is to create a Maven profile with your settings, then activate this profile when building on CI.

Example profile:

<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>

Example how to enable it on TeamCity: mvn checkstyle:check -Pci

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.



来源:https://stackoverflow.com/questions/38219771/override-the-dependency-version-used-at-runtime-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!