在 Maven 2 的命令行中设置插件的版本
Posted
技术标签:
【中文标题】在 Maven 2 的命令行中设置插件的版本【英文标题】:Set plugin’s version on the command line in Maven 2 【发布时间】:2010-05-20 04:42:32 【问题描述】:我生成默认的快速入门 Maven 示例,并输入 mvn checkstyle:checkstyle
,它总是尝试使用最新的 SNAPSHOT
版本。可能在我的 Nexus 服务器中是错误的,但是如何,例如 2.5
用于 checkstyle 而不是 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
我猜可能是mvn checkstyle:2.5:checkstyle
,可惜不是。
当然,如果我在pom.xml
中设置构建依赖关系,它会起作用,但我想看看命令行如何工作。
【问题讨论】:
如果我输入完整的工件,它可以工作 mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.5:checkstyle 【参考方案1】:如果您不想运行安装在本地存储库中的最新版本的插件,则需要设置版本号。为此,您需要以以下形式指定一个完全合格的目标:
mvn groupID:artifactID:version:goal
所以在你的情况下:
mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.5:checkstyle
【讨论】:
“运行安装在本地存储库中的最新版本的插件”似乎不是真的。我的本地仓库中有maven-dependency-plugin
2.8
、2.10
和3.0.0
,Maven 默认运行2.8
。即使我删除了2.8
Maven 也会在下次运行时重新下载。【参考方案2】:
我对新版本 maven(3.3.9) 的体验略有不同。如果我没有在离线模式下运行 maven,它总是会去远程仓库,不管我在本地有什么。 如果它找到一个更新的版本(基于 maven-metadata.xml),它会下载并使用那个版本。更重要的是,它会同时扫描多个repos:
[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)
更重要的是,maven 似乎知道如何比较几个元数据文件并选择最新版本的工件。
根据我在resolver-status.properties
中看到的内容,Maven 使用 Aether 来解决依赖关系:
#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=
【讨论】:
【参考方案3】:mvn org.apache.maven.plugins:maven-site-plugin:3.7.1:site
【讨论】:
欢迎来到 Stack Overflow,感谢您的回答。最好的答案会为代码或命令添加一点解释。你可以edit这个答案来改进它。【参考方案4】:你也可以使用:
mvn your groupId:your artifactId:your version:your goal
【讨论】:
以上是关于在 Maven 2 的命令行中设置插件的版本的主要内容,如果未能解决你的问题,请参考以下文章
在`pygments`的命令行工具`pygmentize`中设置html字体大小
如何在 BQ 命令行中设置 Bigquery 需要分区过滤器