Set plugin’s version on the command line in Maven 2
Asked Answered
S

4

49

I generate default quickstart Maven example, and type mvn checkstyle:checkstyle, it always try to use the lastest SNAPSHOT version. Probably it is wrong in my Nexus server, but how can I set plugin's version on the command line in Maven 2, like 2.5 for checkstyle instead of 2.6-SNAPSHOT?

C:\HelloWorld>mvn checkstyle:checkstyle
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'checkstyle'.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: org.apache.maven.plugins:maven-checkstyle-plugin

Reason: Error getting POM for 'org.apache.maven.plugins:maven-checkstyle-plugin' from  the repository: Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.
  org.apache.maven.plugins:maven-checkstyle-plugin:pom:2.6-SNAPSHOT

from the specified remote repositories:
  nexus (http://localhost:9081/nexus/content/groups/public)

for project org.apache.maven.plugins:maven-checkstyle-plugin

I guess it could be mvn checkstyle:2.5:checkstyle, unfortunately it is not.

Surely if I set build dependance in pom.xml, it will work, but I want to see how command line can work.

Sterilant answered 20/5, 2010 at 4:42 Comment(1)
If I type in complete artifact, it works mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.5:checkstyleSterilant
V
81

If you don't want to run the latest version of a plugin installed in your local repository, you need to set the version number. And for that, you need to specify a fully-qualified goal in the form of:

mvn groupID:artifactID:version:goal

So in your case:

mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.5:checkstyle
Valleau answered 20/5, 2010 at 10:17 Comment(1)
"run the latest version of a plugin installed in your local repository" seems not to be true. I have maven-dependency-plugin 2.8, 2.10 and 3.0.0 in my local repo and Maven runs 2.8 by default. Even if I delete 2.8 Maven re-downloads it at the next run.Sniper
Z
3

My experience with a newer version of maven(3.3.9) is slightly different. If I'm not running maven in offline mode, it will ALWAYS go for a remote repo regardless of what I have in the local one. And if it finds a newer version(based on maven-metadata.xml), it will download and use that one. What's more, it will scan multiple repos simultaneously:

[INFO] ------------------------------------------------------------------------
[DEBUG] Resolving plugin version for com.phoenixnap.oss:springmvc-raml-plugin
[DEBUG] Could not find metadata com.phoenixnap.oss:springmvc-raml-plugin/maven-metadata.xml in local (/home/yuranos/.m2/repository)
[DEBUG] Using transporter WagonTransporter with priority -1.0 for https://repo.spring.io/libs-milestone
[DEBUG] Using transporter WagonTransporter with priority -1.0 for https://repo.spring.io/milestone
[DEBUG] Using transporter WagonTransporter with priority -1.0 for https://repo.maven.apache.org/maven2
[DEBUG] Using transporter WagonTransporter with priority -1.0 for https://repo.spring.io/snapshot
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://repo.spring.io/libs-milestone
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://repo.spring.io/milestone
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://repo.maven.apache.org/maven2
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://repo.spring.io/snapshot
Downloading: https://repo.spring.io/libs-milestone/com/phoenixnap/oss/springmvc-raml-plugin/maven-metadata.xml
Downloading: https://repo.spring.io/snapshot/com/phoenixnap/oss/springmvc-raml-plugin/maven-metadata.xml
Downloading: https://repo.maven.apache.org/maven2/com/phoenixnap/oss/springmvc-raml-plugin/maven-metadata.xml
Downloading: https://repo.spring.io/milestone/com/phoenixnap/oss/springmvc-raml-plugin/maven-metadata.xml
[DEBUG] Writing tracking file /home/yuranos/.m2/repository/com/phoenixnap/oss/springmvc-raml-plugin/resolver-status.properties
[DEBUG] Writing tracking file /home/yuranos/.m2/repository/com/phoenixnap/oss/springmvc-raml-plugin/resolver-status.properties
Downloaded: https://repo.maven.apache.org/maven2/com/phoenixnap/oss/springmvc-raml-plugin/maven-metadata.xml (2 KB at 1.0 KB/sec)
[DEBUG] Writing tracking file /home/yuranos/.m2/repository/com/phoenixnap/oss/springmvc-raml-plugin/resolver-status.properties
Downloaded: https://repo.spring.io/libs-milestone/com/phoenixnap/oss/springmvc-raml-plugin/maven-metadata.xml (2 KB at 0.9 KB/sec)
[DEBUG] Writing tracking file /home/yuranos/.m2/repository/com/phoenixnap/oss/springmvc-raml-plugin/resolver-status.properties
[DEBUG] Could not find metadata com.phoenixnap.oss:springmvc-raml-plugin/maven-metadata.xml in spring-snapshots (https://repo.spring.io/snapshot)
[DEBUG] Could not find metadata com.phoenixnap.oss:springmvc-raml-plugin/maven-metadata.xml in spring-milestones-libs (https://repo.spring.io/milestone)

What's more, maven seems to know how to compare several metadata files and select the very latest version of the artifact. Maven makes use of Aether to resolve dependencies, based on what I see in resolver-status.properties:

    #NOTE: This is an Aether internal implementation file, its format can be changed without prior notice.
#Mon Feb 19 23:41:24 EET 2018
maven-metadata-spring-milestones.xml.lastUpdated=1519076484366
maven-metadata-spring-snapshots.xml.error=
maven-metadata-central.xml.lastUpdated=1519076484205
maven-metadata-spring-snapshots.xml.lastUpdated=1519076484107
maven-metadata-spring-milestones-libs.xml.lastUpdated=1519076484105
maven-metadata-spring-milestones-libs.xml.error=
Zootomy answered 19/2, 2018 at 21:35 Comment(0)
M
3
mvn org.apache.maven.plugins:maven-site-plugin:3.7.1:site
Mascagni answered 5/10, 2018 at 2:51 Comment(1)
Welcome to Stack Overflow, and thanks for your answer. The best answers add a little explanation to the code or command. You could edit this answer to improve it.Hypothermia
C
0

You can also use:

mvn {your groupId}:{your artifactId}:{your version}:{your goal}

Contrail answered 14/2, 2018 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.