Maven update version of specific dependency

£可爱£侵袭症+ 提交于 2019-12-10 11:40:35

问题


I am trying to update the version of particular dependency in my Spring Boot project using the below command. However the dependency version is not getting updated. This is the command I am using:

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

Spring Boot project's dependency:

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

My local Maven repository .m2 folder contains 2 versions of drools-sample-proj:

  • 0.0.2-SNAPSHOT
  • 0.0.3-SNAPSHOT

My Spring Boot's project pom.xml is not getting updated for that dependency with 0.0.3-SNAPSHOT with this build command:

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

Build console logs:

[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 version: 1.5.9

Spring Boot project's pom.xml:

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

I am using embedded Maven in Spring STS IDE. Am I missing anything here or my understanding on update of pom.xml is incorrect? Any insights would be helpful.

Logs after using mvn use-latest-versions command.

I am getting an exception when using this command: mvn versions: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:


The goal versions:use-latest-snapshots updates only release versions, see Advancing dependency versions :

versions:use-latest-snapshots searches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the latest -SNAPSHOT version.

but in your POM is a snapshot version:

Spring Boot project's dependency:

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

so the dependency is not changed.

You could use the goal versions:use-latest-versions, see Versions Maven Plugin :

Replaces any version with the latest version.

Your modified command line:

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


来源:https://stackoverflow.com/questions/48605114/maven-update-version-of-specific-dependency

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