Java – Maven Release Plugin aborts prepare because of local modifications in jenkins

javaJenkinsmavenmaven-release-pluginsvn

Problem:

When I execute the prepare goal of maven release plugin I get the error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project my-artifact-id: Cannot prepare the release because you have local modifications :

[ERROR] [my-project-name\src\main\java\some\packages\SomeJavaSourceFile.java:modified]

[ERROR] [my-project-name\src\main\java\some\packages\SomeOtherJavaSourceFile.java:modified]

for something about 20 files.

Details

  • The release plugin is executed from Jenkins.
  • SVN is configured as "always check out a fresh copy"
  • Maven release plugin is used with the goal -Dresume=false clean release:prepare release:perform
  • The modified files were modified in the last commits.
  • The error occurs during execution of the prepare goal:

    [INFO] — maven-release-plugin:2.3.2:prepare (default-cli) @ artifact-id

  • The release plugin ran sucessfully in the past 11 times (but sometimes it doesn't work on the first try, but on the second)

Similar Questions

Why other questions doesn't help:

Log

I tried to anonymize it, so you find some parts replaced with [meaning of replaced part]

Started by user Sergej Werfel
[EnvInject] - Loading node environment variables.
Building remotely on Build in workspace E:\Jenkins\Build\workspace\project-dir
Cleaning local Directory .
Checking out [svn-url] at revision '2016-09-09T10:12:55.444 +0200'
...
A         some file
...
AU        some other file
AU        pom.xml
AU        event more files
...
 U        .
At revision 1639745
no change for [svn-url] since the previous build
Injecting SonarQube environment variables using the configuration: Sonar 5
Parsing POMs
Injecting SonarQube environment variables using the configuration: Sonar 5
using global settings config with name MVN Settings [setting name]
Replacing all maven server entries not found in credentials list is true
Injecting SonarQube environment variables using the configuration: Sonar 5
Injecting SonarQube environment variables using the configuration: Sonar 5
Injecting SonarQube environment variables using the configuration: Sonar 5
Injecting SonarQube environment variables using the configuration: Sonar 5
Injecting SonarQube environment variables using the configuration: Sonar 5
Injecting SonarQube environment variables using the configuration: Sonar 5
Injecting SonarQube environment variables using the configuration: Sonar 5
Established TCP socket on 18423
maven32-agent.jar already up to date
maven32-interceptor.jar already up to date
maven3-interceptor-commons.jar already up to date
[project name] $ "C:\Program Files\Java\jdk1.8.0_51/bin/java" -cp E:\Jenkins\Build\maven32-agent.jar;C:\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar;C:\apache-maven-3.3.9/conf/logging jenkins.maven3.agent.Maven32Main C:\apache-maven-3.3.9 E:\Jenkins\Build\slave.jar E:\Jenkins\Build\maven32-interceptor.jar E:\Jenkins\Build\maven3-interceptor-commons.jar 18423
<===[JENKINS REMOTING CAPACITY]===>channel started
using global settings config with name MVN Settings [setting name]
Replacing all maven server entries not found in credentials list is true
Executing Maven:  -B -f [path to root pom]\pom.xml -gs [path to settings]\global-settings1467677761792043752.xml -DdevelopmentVersion=0.1.13-SNAPSHOT -DreleaseVersion=0.1.12 -Dresume=false -DdryRun=true clean release:prepare
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] [project name]
[INFO] module-1
[INFO] module-2
[INFO] module-3
[INFO] module-4
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building root project name 0.1.12-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ root-project ---
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module-1 0.1.12-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-1 ---
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module-2 0.1.12-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-2 ---
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module-3 0.1.12-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-3 ---
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module-4 0.1.12-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-4 ---
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building project name 0.1.12-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-release-plugin:2.3.2:prepare (default-cli) @ root-project ---
[INFO] Verifying that there are no local modifications...
[INFO]   ignoring changes on: **\pom.xml.next, **\release.properties, **\pom.xml.branch, **\pom.xml.tag, **\pom.xml.backup, **\pom.xml.releaseBackup
[INFO] Executing: cmd.exe /X /C "svn --non-interactive status"
[INFO] Working directory: E:\Jenkins\Build\workspace\project-dir
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] root-project ................................ FAILURE [  1.016 s]
[INFO] module-1 .......................... SUCCESS [  0.047 s]
[INFO] module-2 ............................ SUCCESS [  0.049 s]
[INFO] module-3 ....................... SUCCESS [  0.084 s]
[INFO] module-4 ........................ SUCCESS [  0.068 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.089 s
[INFO] Finished at: 2016-09-09T10:13:08+02:00
[INFO] Final Memory: 15M/234M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project root-project: Cannot prepare the release because you have local modifications :
[ERROR] [module-1\src\test\java\package\SomeJavaTest.java:modified]
[ERROR] [... some other files ...]
[ERROR] [module-2\src\main\java\package\SomeJavaFile.java:modified]
[ERROR] [... some other files ...]
[ERROR] [module-2\src\test\java\package\AnOtherTestTest.java:modified]
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[JENKINS] Archiving E:\Jenkins\Build\workspace\project-dir\module-1\pom.xml to [some path]/0.1.12-SNAPSHOT/module-1-0.1.12-SNAPSHOT.pom
[other modules]
[M2Release] its only a dryRun, no need to mark it for keep
channel stopped
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE

Project structure

- root-dir
|- module-1-dir
|'- module-1-pom
|- module-2-dir
|'- module-1-pom
| ...
'-root-pom

Best Answer

Overview

The committed files had only \n( = lf = line feed) as line ending in subversion. They were checked out on a windows machine, so the ending became \r\n(= crlf = carriage return and line feed). So the files have changed ere found as "modified". To fix that check in that files with \r\n-ending directly.

Way to find

  • After a fresh checkout on Jenkins you can run "svn status" as skript to see, that exaclty that files are marked as "modified.
  • When you call "svn diff" you will see, that each files differs in each line, but you see no differences => non visible change
  • open one such modified file from jenkins workspace and one from svn repo and look at them with an editor that can visualize non visible characters (e.g. Notepad++ with "show all characters" from toolbar)

Reason

The reason why this happens is a wrong usage of git-svn. I checked out that files with git-svn without changing the "autocrlf" setting. Git changes the ending to \n when committing to local repo. When pushing to svn the line ending remains \n.

Fix

  • Checkout with a svn client, change line endings, commit.
  • or set "autocrlf" to false in git. Check out with git-svn, change line-endings, dcommit.

How to avoid in future

Git has a setting "autocrlf". Turning it of seems to fix the problem