2010-05-20 14 views
28

Je génère un exemple Maven quickstart par défaut, et tapez mvn checkstyle:checkstyle, il essaie toujours d'utiliser la dernière version SNAPSHOT. Probablement que c'est faux sur mon serveur Nexus, mais comment puis-je définir la version du plugin sur la ligne de commande dans Maven 2, comme 2.5 pour checkstyle au lieu de 2.6-SNAPSHOT?Définir la version du plugin sur la ligne de commande dans Maven 2

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 

Je pense que cela pourrait être mvn checkstyle:2.5:checkstyle, malheureusement ce n'est pas. Sûrement si je place la dépendance de construction dans pom.xml, cela fonctionnera, mais je veux voir comment la ligne de commande peut fonctionner.

+0

Si je tape dans artéfact, il fonctionne mvn org.apache.maven.plugins: maven-plugin-checkstyle: 2.5 : checkstyle –

Répondre

53

Si vous ne souhaitez pas exécuter la dernière version d'un plug-in installé dans votre référentiel local, vous devez définir le numéro de version. Et pour cela, vous devez spécifier un objectif entièrement qualifié sous la forme de:

mvn groupID:artifactID:version:goal 

Donc dans votre cas:

mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.5:checkstyle 
+0

"_run la dernière version d'un plug-in installé dans votre référentiel local_" ne semble pas être vrai. J'ai 'maven-dependency-plugin'' 2.8', '2.10' et' 3.0.0' dans mon repo local et Maven exécute '2.8' par défaut. Même si je supprime '2.8', Maven le télécharge au prochain lancement. –

0

Vous pouvez également utiliser:

mvn { votre groupId}: {votre version d'artefact}: {votre version}: {votre objectif}

0

Mon expérience avec une version plus récente de maven (3.3. 9) est légèrement différent. Si je n'utilise pas maven en mode déconnecté, il faudra TOUJOURS opter pour un repo distant indépendamment de ce que j'ai dans le local. Et s'il trouve une version plus récente (basée sur maven-metadata.xml), il va télécharger et utiliser celui-là. De plus, il va scanner plusieurs prises en pension simultanément:

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

De plus, maven semble savoir comment comparer plusieurs fichiers de métadonnées et sélectionnez la toute dernière version de l'artefact. Maven utilise Aether pour résoudre les dépendances, sur la base de ce que je vois dans 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=