Maven release:prepare-with-pom non-interactive

2019-04-10 04:00发布

问题:

I'm trying to release a project with Maven.

My project POM is containing -SNAPSHOT dependencies, so in order to perform the release automatically, I want to use the following maven command, based on the "maven-release-plugin" goals: mvn release:prepare-with-pom in order to prepare the project's pom.xml for releasing and resolve dependencies -SNAPSHOT versions automatically without edit them by hand.

Unfortunately I found this is working only in interactive mode from command line. The idea is that I'm wondering if this can be done without any manual interaction. I am using Bamboo as CI Server and I want to have this into a plan and perform this project releasing automatically. The --non-interactive or -B argument isn't working, actually if I'm using -B or --non-interactive argument the maven goal is failing.

This is the output for mvn release:prepare-with-pom:

H:\APPS\dev\cmtest\test-dependency\trunk>mvn release:prepare-with-pom -DdryRun=t
rue
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building test-dependency 0.0.4-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.0:prepare-with-pom (default-cli) @ test-depend
ency ---
[INFO] Resuming release from phase 'check-dependency-snapshots'
[INFO] Checking dependencies and plugins for snapshots ...
There are still some remaining snapshot dependencies.: Do you want to resolve th
em now? (yes/no) no: : yes
Dependency type to resolve,: specify the selection number ( 0:All 1:Project Depe
ndencies 2:Plugins 3:Reports 4:Extensions ): (0/1/2/3) 1: : 1
Resolve Project Dependency Snapshots.: '${artifactGroup}:${artifactId}' set to releas
e? (yes/no) yes: : yes
What is the next development version? (0.1.3-SNAPSHOT) 0.1.3-SNAPSHOT: :
'${artifactGroup}:${artifactId1}_1' set to release? (yes/no) yes: : yes
What is the next development version? (0.0.2-SNAPSHOT) 0.0.2-SNAPSHOT: :
'${artifactGroup}:parent-pom' set to release? (yes/no) yes: : yes
What is the next development version? (0.0.3-SNAPSHOT) 0.0.3-SNAPSHOT: :
What is the release version for "test-dependency"? (${artifactGroup}:${artifactId1}_2) 0.0.4: :
What is SCM release tag or label for "test-dependency"? (${artifactGroup}:${artifactId1}_2) test-dependency-0.0.4: :
What is the new development version for "test-dependency"? (${artifactGroup}:${artifactId1}_2) 0.0.5-SNAPSHOT: :
[INFO] Transforming '${artifactId1}_2'...
[INFO] Updating ${artifactId1}_1 to 0.0.1
[INFO] Updating ${artifactId1} to 0.1.2
[INFO] Generating release POMs...
[INFO] Generating release POM for 'test-dependency'...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

So, can you help me please to find a trick in order to perform this maven command in non-interactive mode? Thanks a lot

回答1:

While your pom refers to snapshot releases I don't believe non-interactive is possible (maybe a fancy 'expect' script but that might be a bit much).

Releasing a library that relies on snapshots is very dangerous because the libraries can change from under your feet. Anyone using your library is going to assume that every time they use it they're getting the same jars, with the same SHAs, but in reality that's not the case. That's why maven makes it nearly impossible do to this.

I'd recommend concentrating on moving your dependencies to released versions, or if that's not an option, keeping your library as a snapshot. Keeping your library as a snapshot means that your clients are at least aware that the libraries they're using can change without their knowledge.