active a profile during release prepare in maven 3 does not work - maven

I have a need to active a profile during release:prepare.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<arguments>-Prelease</arguments>
<preparationGoals>clean validate</preparationGoals>
<goals>test-compile</goals>
</configuration>
</plugin>
</plugin>
</build>
But when I run:
mvn release:prepare -DdryRun=true help:active-profiles
it never show profile release in active list. and it is not show up on active profile list when I do:
mvn release:perform help:active-profiles
I could not not use <releaseProfiles> since I want this profile to be used in both prepare and perform
Thanks!

One thing that I have used in this case is not using the -P argument, but rather triggering the profile through an environment setting using -Denv=release. Then in the POM, I have the profile activation based on the value of env. This has always worked for me. So in the arguments parameter, you could put something like
<arguments>-Denv=release</arguments>
Similar questions can be found here:
Profile activation on both release:prepare and release:perform
maven release plugin ignores releaseProfile

I think there's some misunderstanding here: mvn release:prepare -DdryRun=true help:active-profiles will never show the active profiles used during the release, but it shows the current active profiles. release:prepare will start another Maven thread (separate executable), and only then the release profile is activated.
In the maven-release-plugin-2.4 a lot has been fixed with regards to profiles, especially for Maven3, since some information was not available anymore when using Maven 2 but now is with Maven 3.
See the release notes

Related

Maven release plugin executes tests twice

When release:clean release:prepare release:perform is executed , the tests are executed twice
Once at release:prepare , stage run-preparation-goals , task clean verify
And another time on release:perform ,stage run-perform-goals , task deploy
Is there any configuration option to make tests run only on first one and not being executed on perform?
BR
Yulian Oifa
That's because 2 full builds are run as part of the commands you issue.
The release:prepare section performs lots of checks on the code & repository, and does a full build to ensure all tests pass.
The release:perform section tags the repo, then pulls that tag. It performs a build based on that tag and the releases that build to your artefact store of choice (Nexus/Artifactory/wherever).
These steps are designed this way to ensure you don't pollute your repo with a tag on code that doesn't build, and tests are an integral part of your build. Once maven is happy your code is good to go, it creates the tag, and pulls it so it knows for sure that the code being released is the code referenced by the tag, and nothing else. Building that tag for release requires a full build, including the tests.
You can skip the tests on one or other of the steps, or on both, but you're missing the point of tests, and of the release plugin, if you do that.
You can override the goals parameter and add -DskipTests=true.
This parameter will skip the tests only on the perform part.
Eventually i had to change a logic.
I have executed mvn clean install release:clean release:prepare release:perform -Pmaven-release
and create a maven-release. As result the tests are executed only at install
BR
Yulian Oifa
<profile>
<id>maven-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<arguments>-Dmaven.test.skip</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
You can skip running the tests (managed by surefire plugin) with an explicitly specified parameter -DskipTests:
Something like this:
mvn release:perform -DskipTests
For intergration tests (managed by failsafe plugin) you can use a similar flag: -DskipITs
If you don't want even compile the tests you can use -Dmaven.test.skip=true (for both unit and integration tests)

How do I set the SCM tag in the Maven Release Plugin?

When I run the release:prepare Maven goal it asks me for the version three times: release, release, next-snapshot.
Is it possible to force the second one to be always like the first one?
What is the release version for "app1"? (org.dep1:app1) 1.0.9: :
What is the SCM release tag or label for "app1"? (org.dep1:app1) 1.0.9: :
What is the new development version for "app1"? (org.dep1:app1) 1.0.10-SNAPSHOT: :
I would prefer to always have the git tag identical to the version number, and ideally skip the second question.
Here's my Maven Release Plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<tagNameFormat>#{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
The simplest step is to use batch mode which can be done like this:
mvn -B release:prepare release:perform
This will use the defaults without asking for anything.
If you want to set the releaseVersion you can do that via:
mvn -B release:prepare release:perform -DreleaseVersion=2.0.0
To control which development version will be used you can set this by adding-D developmentVersion=2.1.0-SNAPSHOT if you don't like the default.

Skip tests on checkout during maven release:perform

During the maven release:perform goal, the prepared tag is being checked out from SCM and a build seems to be attempted in a forked maven instance.
I'd like the tests to be skipped at that point, because for whatever reason, they fail (the build involves running a test web-application via cargo, and I believe this just doesn't work well in this environment).
Is there any way to instruct maven to do this?
You can specify arguments to the forked maven instance on the command line:
mvn release:prepare -Darguments="-DskipTests"
mvn release:perform -Darguments="-DskipTests"
or specify a maven-release-plugin configuration in your pom, perhaps under pluginManagement:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<arguments>-DskipTests</arguments>
</configuration>
</plugin>

How to list all activated profiles in mvn in a multimodule project

mvn help:active-profiles only list the profiles activate within the project + system settings you call it in.
It does not list the profiles that have been enabled/activated from i.e. the parent pom.
Any any way to actually see the full list of activated profiles by other means than trial-and-error to look at what properties are enabled or not ?
Another option is mvn help:all-profiles, which also list inherited profiles.
Displays a list of available profiles under the current project.
Note: it will list all profiles for a project. If a profile comes up with a status inactive then there might be a need to set profile activation switches/property.
More details in Maven's help plugin page
I double-checked this and indeed, inherited profiles aren't listed when mvn help:active-profiles is being called. This is with maven-help-plugin version 2.1.1.
There is even a bug-report about this: MPH-79.
As a workaround, you can use older version:
mvn org.apache.maven.plugins:maven-help-plugin:2.0.2:active-profiles ...
Do you always want to see the active profile in your build log? Then you could add the following plugin config to the <build> section.
In this example I added the plugin to the phase 'compile'. It could easily be added to a different phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>show-profiles</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
this works in maven 3.x
mvn help:active-profiles
mvn help:effective-profiles
Works to list the active profiles

How can I get maven-release-plugin to skip my tests?

How can I get the maven-release-plugin to run without triggering the tests?
I have tried
-Dmaven.test.skip=true
and
-DskipTests
and
-DpreparationGoals=clean
...yet none work.
Yes, I know I shouldn't release if the tests don't pass, but I don't have control over making my coworkers write reliable tests.
-Darguments="-DskipTests" is what you want, or explicitly configuring the forked executions in the pom.
-Darguments="..." passes arguments to the forked maven process, but it is important to realise that there are two different switches being used here. The -DskipTests forces maven to not run any tests, but the tests are still compiled (this is important if you have any dependencies on a test-jar type). The -Dmaven.test.skip=true forces maven to not even compile the tests, which means that any test-jars will not be generated.
So, you must use -Darguments, but to skip tests running use only skipTests, to stop them compiling use maven.test.skip.
If you just want to skip integration tests, this will do it:
-Darguments="-DskipITs"
you have too differents choices to avoid and skip tests with the release plugin
The first is to pass as argument on cli to the release goal or phases by providing a -Darguments:
exemple: mvn -X -Darguments="-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true" -P release-mode release:prepare
-The second is to perform thoses arguments on your pom.xml in the build like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
<configuration>
<skip>true</skip>
<skipTests>true</skipTests>
<preparationGoals>clean validate</preparationGoals>
<arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true</arguments>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release-mode</releaseProfiles>
<tagNameFormat>TEST-#{project.version}</tagNameFormat>
</configuration>
</plugin>
Note that the second method override the first.
I recommanded you to prepare release first on a single action and then you can edit the release.properties file on the working directorie and look the exec.additionalArguments properties if your arguments are there. It will look like: exec.additionalArguments=-Dmaven.javadoc.skip\=true -Dmaven.test.skipTests\=true -Dmaven.test.skip\=true -P release-mode.
After you can perform the release.
I have managed to avoid running the verify goal by simply adding the configuration preparationGoals to clean:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<preparationGoals>clean</preparationGoals> <!-- See here -->
</configuration>
</plugin>
Use the following argument to skip test
-Darguments="-DskipTests"
or
alternatively skipping by default
[...]
<properties>
<skipTests>true</skipTests>
</properties>
[...]

Resources