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

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

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>

Commit multiple files with maven scm plugin

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

How To Use The Sonar Maven Plug-in

Easy question here. I want to add sonar to be executed on every Maven build. I tried:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
</plugin>
and
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>5.1</version>
</plugin>
and
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7.1</version>
</plugin>
because a) I couldn't figure out what the plug-ins do and/or b) which one is the current one.
If I only add the above to <build> -> <plugins> it's not executed ever (so the plug-in doesn't have a default execution). So of course I added a <execution> instruction, and after that Sonar gets executed, but with the following error message:
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.1.1:sonar (default) on project org.acme.project.build: Can not execute Findbugs: This project contains Java source files that are not compiled.
It does not seem to matter which phase I use (I tried validate and compile and test and prepare-package and package even though not all of them make sense). I am sure there is no source code generation anywhere in the project. And the static classes get compiled just fine.
I think the problem might be that the plug-in gets executed for every module, including the parent pom project. Which is weird, because sonar:sonar skips that project.
But the project structure is simple and I can't find anything unusual about it:
<groupId>group</groupId>
<artifactId>org.acme.project.build</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>org.acme.project</module>
</modules>
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.host.url>http://sonar.acme.org/</sonar.host.url>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The project org.acme.project has nothing besides its own artifact ID and the parent. The command line is: mvn clean deploy -Dsonar.login=Wile.Coyote -Dsonar.password=*********** -Psonar
The log shows that sonar is always executed before the install phase, which of course is way to early.
So how do I use Sonar's Maven plug-in to analyze my code?
a) I couldn't figure out what the plug-ins do
The plugin is used to gather the details from code coverage reports and the repository code scanning for getting to analyze possible bugs, duplications etc. You can search for a sample sonar report to find what all and how to get these details with maven using two methods like settings.xml and maven plugin is detailed at SonarQube Scanner for Maven and
SonarQube - analyzing with Maven
b) which one is the current one.
The maven central suggests that the current plugin from org.codehaus.mojo used as
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
has been moved to
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
So you should ideally be using the one from groupId - org.sonarsource.scanner.maven as also suggested by the SonarQube Docs
Also the artifact from org.codehaus.sonar version 5.1 seems to be outdated and not maintained.

Code Coverage not populated after sonar analysis

I am using sonarqube5.6.1.
I have a multi module project for which i am running sonar analysis using the below command.
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.1.1:sonar -Dsonar.host.url=http://bamboo.in.XXX.com:8085 -Dsonar.analysis.mode=publish -Dsonar.issuesReport.html.enable=true -Dsonar.dynamicAnalysis=false
But code coverage is not getting populated at all.
Can some one help. I could see the below warnings, Not sure if that's the reason.
[INFO] Process project properties
[WARNING] /!\ A multi-module project can't have source folders, so '/ssdd5/sameenud/dev/trunk/AAAA/BBBB/CCCC/DDDD/src/main/java' won't be used for the analysis. If you want to analyse files of this folder, you should create another sub-module and move them inside it.
The folder structure we have is as below,
AAAA
--BBBB
pom.xml
---CCCC
pom.xml
---DDDD
pom.xml
I tried compiling it manual, But no luck, Same problem.
I had the similar issue, 0.0% coverage & no unit tests count on Sonar dashboard with SonarQube 6.7.2:
Maven : 3.5.2,
Java : 1.8,
Jacoco : Worked with 7.0/7.9/8.0,
OS : Windows
After a lot of struggle finding for correct solution, resolved issue with this configuration my parent pom looks like:
<properties>
<!--Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.0.905</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
I've tried few other options like jacoco-aggregate & even creating a sub-module by including that in parent pom but nothing really worked & this is simple. I see in logs <sonar.jacoco.reportPath> is deprecated,but still works as is and seems like auto replaced on execution or can be manually updated to <sonar.jacoco.reportPaths> or latest. Once after doing setup, in cmd start with mvn clean install then mvn org.jacoco:jacoco-maven-plugin:prepare-agent install & then do mvn sonar:sonar , this is what I've tried please let me know if some other best possible solution available.Hope this helps!! If not please post your question..
SonarQube (and more specifically SonarJava analyzer) is not computing the coverage. You have to provide a coverage report in order for the analysis to import its results in the SonarQube UI and display coverage.
See the documentation for more information on how to achieve this.

Installing and compiling Maven artifacts on Java 8

I have a project with a pom.xml that has the following <build> declaration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
When I run mvn install on this project, it compiles the project, runs unit tests and publishes it to my local repo. I am trying to learn a little more about Maven here, and am having a tough time finding documentation/explanations on the following:
How am I able to run mvn install, if the POM doesn't declare it under build/plugins? Does maven-compiler-plugin include maven-install-plugin, if so, how could I have figured that out?
Most importantly: the value of build/plugins/plugin/configuration/source and .../target are both set to 1.8. If my machine has Java 8 on it, and I run mvn install on this project without any errors, does that guarantee that the project builds with Java 8? I'm looking at the docs for the Compiler Plugin and don't see those source/target configs listed anywhere.
First you should learn what the build life cycle is and how it works and how the plugins are bound to the life cycle by default.
Furthermore you should understand that in Maven every project inherits from the super pom file which is part of the maven distribution (the package you have downloaded). The super pom defines the default folder layout and some versions of plugins.
The question to define the maven-compiler-plugin as you did is to be very accurate simply wrong. You should have defined it like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This would overwrite the definition which is inherited by the super pom and changes it's configuration. In your case i would suggest to change the definition into this:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
..
</project>
The encoding should be set globally cause there are other plugins which use this definition like the maven-resources-plugin. The usage of the above property simplifies this, cause every plugin which has an option for encoding will use the default as defined in the property.
To be sure using the correct version of Java (your JDK on your machine) you have to use the maven-enforcer-plugin.
Apart from that please take a look onto the plugins page which shows the most up-to-date releases of the plugins.
As a good documentation i can recomment the Books on Maven but be aware they are written with Maven 2 in mind. So if something is not clear ask on users mailing list of here on SO.

Resources