maven更新版本具体依赖

Posted

技术标签:

【中文标题】maven更新版本具体依赖【英文标题】:Maven update version of specific dependency 【发布时间】:2018-07-14 06:41:29 【问题描述】:

我正在尝试使用以下命令更新我的 Spring Boot 项目中特定依赖项的版本。但是依赖版本没有得到更新。这是我正在使用的命令:

mvn versions:use-latest-snapshots -Dincludes=com.example:drools-sample-proj

Spring Boot 项目的依赖:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>drools-sample-proj</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

我的本​​地 Maven 存储库.m2 文件夹包含两个版本的drools-sample-proj

0.0.2-快照 0.0.3-快照

我的 Spring Boot 项目 pom.xml 没有通过 0.0.3-SNAPSHOT 使用此构建命令更新该依赖项:

mvn versions:use-latest-snapshots -Dincludes=com.example:drools-sample-proj

构建控制台日志:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-rule-service 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- versions-maven-plugin:2.2:use-latest-snapshots (default-cli) @ springboot-ruleservice-api ---
[INFO] Incremental version changes allowed
[INFO] Incremental version changes allowed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.800 s
[INFO] Finished at: 2018-02-03T23:25:58-06:00
[INFO] Final Memory: 23M/377M
[INFO] ------------------------------------------------------------------------

Spring Boot 版本:1.5.9

Spring Boot 项目的pom.xml:

<build>
    <finalName>springboot-rule-service</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我在 Spring STS IDE 中使用嵌入式 Maven。我在这里遗漏了什么,或者我对pom.xml 更新的理解不正确?任何见解都会有所帮助。

使用 mvn use-latest-versions 命令后的日志。

使用此命令时出现异常: mvn 版本:use-latest-versions -Dincludes=com.example.brms:drools-sample-proj -X

[DEBUG]   (s) project = MavenProject: com.example.brms:springboot-ruleservice-api:1.0 @ C:\Drools Workspace\sprinboot-ruleservice-api\pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: com.example.brms:springboot-ruleservice-api:1.0 @ C:\Drools Workspace\springboot-ruleservice-api\pom.xml]
[DEBUG]   (f) remoteArtifactRepositories = [      id: central
      url: http://mavencentral.Xxx.com/content/groups/public/
   layout: default
snapshots: [enabled => true, update => always]
 releases: [enabled => true, update => daily]
]
[DEBUG]   (f) remotePluginRepositories = [      id: central
      url: https://repo.maven.apache.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => never]
]
[DEBUG]   (f) serverId = serverId
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@790132f7
[DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@48b0e701
[DEBUG] -- end configuration --
[INFO] Major version changes allowed
[INFO] Major version changes allowed
[DEBUG] Looking for newer versions of com.example.brms:drools-sample-proj:jar:0.0.1-SNAPSHOT
[DEBUG] Determining update check for artifact com.cccis.brms:tvr-rules (C:\Users\smuthuku\.m2\repository\com\example\brms\drools-sample-proj\maven-metadata-central.xml) from central (http://mavencentral.company.com/content/groups/public/)
[DEBUG] Searching for central.maven-metadata-central.xml.lastUpdated in resolution tracking file.
[DEBUG] Reading resolution-state from: C:\Users\smuthuku\.m2\repository\com\example\brms\drools-sample-proj\resolver-status.properties
[DEBUG] Error releasing shared lock for resolution tracking file: C:\Users\smuthuku\.m2\repository\com\example\brms\drools-sample-proj\resolver-status.properties
**java.nio.channels.ClosedChannelException**
    at sun.nio.ch.FileLockImpl.release(FileLockImpl.java:58)
    at org.apache.maven.repository.legacy.DefaultUpdateCheckManager.read(DefaultUpdateCheckManager.java:396)
    at org.apache.maven.repository.legacy.DefaultUpdateCheckManager.readLastUpdated(DefaultUpdateCheckManager.java:323)
    at org.apache.maven.repository.legacy.DefaultUpdateCheckManager.readLastUpdated(DefaultUpdateCheckManager.java:159)
    at org.apache.maven.repository.legacy.DefaultUpdateCheckManager.isUpdateRequired(DefaultUpdateCheckManager.java:148)
    at org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager.resolve(DefaultRepositoryMetadataManager.java:124)
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveAvailableVersions(MavenMetadataSource.java:434)
    at org.apache.maven.project.artifact.MavenMetadataSource.retrieveAvailableVersions(MavenMetadataSource.java:424)
    at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupArtifactVersions(DefaultVersionsHelper.java:389)
    at org.codehaus.mojo.versions.UseLatestVersionsMojo.useLatestVersions(UseLatestVersionsMojo.java:128)
    at org.codehaus.mojo.versions.UseLatestVersionsMojo.update(UseLatestVersionsMojo.java:95)
    at org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo.process(AbstractVersionsUpdaterMojo.java:322)
    at org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo.execute(AbstractVersionsUpdaterMojo.java:257)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] artifact com.example.brms:drools-sample-proj: checking for updates from central
[DEBUG] repository metadata for: 'artifact com.example.brms:drools-sample-proj' could not be found on repository: central
[DEBUG] Reading resolution-state from: C:\Users\smuthuku\.m2\repository\com\example\brms\drools-sample-proj\resolver-status.properties
[DEBUG] Writing resolution-state to: C:\Users\smuthuku\.m2\repository\com\example\brms\drools-sample-proj\resolver-status.properties
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.246 s
[INFO] Finished at: 2018-02-06T10:59:17-06:00
[INFO] Final Memory: 23M/310M
[INFO] ------------------------------------------------------------------------

【问题讨论】:

【参考方案1】:

目标versions:use-latest-snapshots只更新release版本,见Advancing dependency versions :

versions:use-latest-snapshots 在 pom 中搜索所有已是较新 -SNAPSHOT 版本的非 SNAPSHOT 版本,并用最新的 -SNAPSHOT 版本替换它们。

但是在你的 POM 中是一个快照版本:

Spring Boot 项目的依赖:

<dependency>
     <groupId>com.example</groupId>
     <artifactId>drools-sample-proj</artifactId>
     <version>0.0.1-SNAPSHOT</version>
</dependency>

所以依赖关系没有改变。

你可以使用目标versions:use-latest-versions,见Versions Maven Plugin :

用最新版本替换任何版本。

你修改后的命令行:

mvn versions:use-latest-versions -DallowSnapshots=true -Dincludes=com.example:drools-sample-proj

【讨论】:

忽略我之前的帖子。它现在起作用了。我错过了-DallowSnapshots=true。我的 pom.xml 现在已正确更新。非常感谢。 com.example.brmsdrools-sample-proj0.0.3-SNAPSHOT依赖>【参考方案2】:

这个我用过,这个命令会更新pom中的所有版本!

mvn versions:display-dependency-updates

【讨论】:

这个命令只显示可用的新版本依赖,不会更新你的pom。

以上是关于maven更新版本具体依赖的主要内容,如果未能解决你的问题,请参考以下文章

创建发布版本后如何管理 Maven 依赖工件

maven更新版本具体依赖

maven 快照 更新策略

在 POM 中更新依赖版本

IDEA 2020.1 版自动导入MAVEN依赖的方法(新版MAVEN无法自动导入更新POM依赖MAVEN设置自动更新自动

服务器安装新版本R及Seurat方法