Commit multiple files with maven scm plugin - maven

I want to git commit two files in different folders with maven scm plugin (v1.9.4). Eg: abc/p.json and xyz\p.json. I dont want to commit any other files such as other/p.json
According to the documentation for the chekin goal, a comma separated list such as abc/p.json,xyz/p.json should work. But it ends up commiting all the files.
I am using the scm:checkin goal with the maven release plugin's <preparationGoals> configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.release.plugin.version}</version>
<configuration>
<preparationGoals>
clean verify
scm:checkin -DpushChanges=false -Dmessage="[maven-release-plugin] Update version text"
-Dincludes="abc/p.json,xyz/p.json"
</configuration>
</plugin>
How do I commit just the abc/p.json and xyz/p.json files?

I was able to get a list of files checked in by creating a profile, similar to:
<profile>
<id>commit-changed-files</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<configuration>
<includes>file1,file2,file3,file4</includes>
<message>[maven-release-plugin] commit changed files</message>
<pushChanges>false</pushChanges><!-- because I use git -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
And then, in the release plugin configuration:
<preparationGoals>-Pcommit-changed-files clean scm:add scm:checkin</preparationGoals>
<completionGoals>-Pcommit-changed-files clean scm:add scm:checkin</completionGoals>
Reference: formatter-m2e-configurator's pom.xml

Related

Maven release plugin scmReleaseCommitComment parameter

I am using maven release plugin for automated releases from Jenkins without any Jenkins-plugins. Release commit, tag and development commit are created in Git and released project is deployed to Nexus.
What I try to achieve is to change the release commit message. As of release plugin documentation there is an option scmReleaseCommitComment, which is per default #{prefix} prepare release #{releaseLabel}. Maven command look like following and all variables are non empty values.
mvn -f ${projectpath}pom.xml release:clean release:prepare release:perform -DreleaseVersion=${RELEASE_VERSION} -DdevelopmentVersion=${DEVELOPMENT_VERSION}-SNAPSHOT -Dtag=v${RELEASE_VERSION} -DscmReleaseCommitComment=${RELEASE_COMMENT}
Adding scmReleaseCommitComment does no effect and commits are still done with default message. What am I missing here?
That feature was introduced in version 3.0.0-M1 of the maven-release-plugin. You can set it to the latest version in the <plugins> section of your pom.xml, as in the example bellow:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
[...]
</plugins>
Not that you can set the scmReleaseCommitComment in the command line as you showed in your question, using mvn ... release:perform ...-DscmReleaseCommitComment=${MY_RELEASE_COMMENT}, or you can set it in pom.xml:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<scmReleaseCommitComment>#{prefix} my comment #{releaseLabel}</scmReleaseCommitComment>
</configuration>
</plugin>
[...]
</plugins>

maven JaCoCo for site phase only

We have JaCoCo working in our POM and it runs and reports every time we run clean install.
What we would really like to do is only run JaCoCo when a maven site is run.
I have tried adding:
...
<configuration>
<skip>${jacoco.skip}</skip>
....
And setting jacoco.skip to true for the build phase, but in the reporting section, I have added:
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<skip>false</skip>
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
...
But this does not work. Setting jacoco.skip to true does prevent JaCoCo running on normal maven clean install's but also appears to affect the reporting.
Question: How would I configure maven so that JaCoCo runs successfully for a maven site, but does not run for a mvn clean install?
The simplest way is to delegate it to a Maven profile, removing its configuration for your build section and placing it into a profile as following:
<profiles>
<profile>
<id>jacoco</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<configuration><!-- here --></configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
</plugin>
</plugins>
</reporting>
</profile>
</profiles>
You can then add your custom configuration there.
Then normal builds will not apply it, while you could always activate it via:
mvn clean install -Pjacoco
or
mvn site -Pjacoco

Intellij 13.1.2 not unpacking exploded (sub-) artifacts

With Intellij < 13.1.2 we were able to locally have a exploded artifact with exploded subartifacts for development, the actual version 13.1.2 is putting out *.jar and *.war files instead of directories.
I found this workaround in their bugtracker: http://youtrack.jetbrains.com/issue/IDEA-124353
but was wondering how to achieve this for all modules, instead of having to list all of them?
Ok, I found my workaround by adding a maven profile for intellij and enabling it:
<profiles>
<profile>
<id>intellij</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<unpackTypes>war,ejb</unpackTypes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Maven release:prepare : Cannot prepare the release because you have local modifications

I'm facing a problem with continuum's release:prepare phase which fails in scm-check-modifications step with error :
[ERROR] org.apache.maven.shared.release.ReleaseFailureException:
Cannot prepare the release because you have local modifications :
[pom.xml:modified]
What i did :
I commited all my changes (*.java and pom.xml) into SVN
I made a build of the project in Continuum
I launched the preparation of the release.
I know that the scm-check-modifications calls ScmCheckModificationsPhase class that verifies that there are no local changes compared to what is on the SCM.
I understand if i'm working with only Maven, if there are some locally changes, or any differences between the local code and the SVN for example, release:prepare won't work, because it checks for modifications first; but working with Continuum,i don't know why it should be a differencse between the local code and the SVN repository ? So i don't know why the release:prepare goal in Continuum is facing that problem.
Example of my pom :
<build>
<plugins>
...
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
</configuration>
</plugin>
...
</plugins>
</build>
<scm>
<connection>scm:cvs:ext:url:/var/cvs:application_name</connection> <developerConnection>scm:cvs:ext:url:/var/cvs:application_name</developerConnection>
</scm>
.....
</project>
In the parent pom.xml:
...
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<goals>deploy</goals>
<arguments>-Prelease</arguments>
</configuration>
</plugin>
.....
For information, the build and the release of the project is always working fine, until now.
There is a Bypass solution that solved my issue but i still seeking to understand the origin of this problem.
The bypass solution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<configuration>
...
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
I can confirm, that adding the plugin or configuring it to exclude the pom.xml check did work:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
Removing my project's target folder from source control fixed this issue for me.
For everybody who don't want to change the pom.xml a commandline option does the trick:
mvn [...] -DcheckModificationExcludeList=pom.xml,.maven/spy.log
I had the problem on our hudson / jenkins CI environment which complained about changes in the .maven/spy.log
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
<checkModificationExclude>**</checkModificationExclude>
</checkModificationExcludes>
</configuration>
For me solution is staging and commiting pom.xml or any other changed file to push git
This is just a workaround for the error . i faced same error with maven-release plugin version 2.5.3 and just sorted the error with maven-release 2.3.2

exclude TestNG-Groups on maven build in hudson

I want to use hudson to build a maven-java project. Some of my integration tests use servers which are not reachable from the hudson-server. So i want to exclude them using a special profile.
<profile>
<id>hudson</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<excludedGroups>ticketserver,print</excludedGroups>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profile
Unfortunatly i am already excluding a group in my general pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.10</version>
<configuration>
<excludedGroups>manual</excludedGroups>
</configuration>
Using mvn help:effective-pom i found out, that this setting overrides the one from my profile. Is there are way exclude all three test-classes when running in the hudson profile?
I though about putting the failsage-configuration in to every profile i have and removing it from the general pom but that does seem right, as i would need to repeat it for every profile i have.
Any help is greatly appreciated
Solved this by defining a property "testGroupsToSkip", which is set in the main-pom. it is then used as the value for excludedGroups. In my Profile i overwrite the property with the new value.

Resources