How to resume failed Maven release:prepare from a subsequent phase (and not the failing one)? - maven

I'm running "mvn release:prepare" and have a failure on phase 11, 'scm-commit-release' due to my scm provider (RTC aka jazz) having problems with my loaded workspace:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M1:prepare
(default-cli) on project driver-component-root-pom: Unable to commit files
[ERROR] Provider message:
[ERROR] Error code for Jazz SCM create changeset command - 9
[ERROR] Command output:
[ERROR] Problem running 'create changeset':
[ERROR] Cannot determine which component to create change set in. Specify a component.
I manually performed equivalent commit operations, and would like to resume building with "-rf release:prepare".
I notice that when building this way, however, Maven knows to start exactly at phase 11/17, and fails again.
[INFO] --- maven-release-plugin:3.0.0-M1:prepare (default-cli) # driver-component-root-pom ---^
[INFO] phase verify-release-configuration
[INFO] starting prepare goal, composed of 17 phases: check-poms, scm-check-modifications,
check-dependency-snapshots, create-backup-poms, map-release-versions, input-variables,
map-development-versions, rewrite-poms-for-release, generate-release-poms, run-preparation-goals,
scm-commit-release, scm-tag, rewrite-poms-for-development, remove-release-poms,
run-completion-goals, scm-commit-development, end-release
[INFO] Resuming release from phase 'scm-commit-release'
[INFO] [prepare] 11/17 scm-commit-release
[INFO] Checking in modified POMs...
.
.
.
(fails exactly the same way again)
I'd like to use "-rf release:prepare" and have Maven start at either phase 12/17 'scm-tag' or 13/17 'rewrite-poms-for-development' and continue onward. (See Maven Release manager prepare phases.)
Two questions: Is this possible to do? How does Maven know how to resume with the particular 'scm-commit-release' phase and not earlier phases?
(Thinking the latter could be hacked to replace 'scm-commit-release' with the desired subsequent phase.)
Thanks.

Well, duh. Figures after I post the question I find something.
I knew there was a 'release.properties' file, but i didn't read it closely enough. Found this encouraging line in it after the third time looking at it:
completedPhase=run-preparation-goals
(I was grepping files for 'phase' and the failed phase name)
I changed that to the phase I wanted to start at, and success! The mvn -rf begins at the phase I wanted it to restart at.

Related

Maven and Sonarqube

A few basic questions on ci/cd pipelines.
When we build java code, do we create jar file before going for sonarqube analysis or does both happen simultaneously. My understanding is sonarqube analysis needs to be performed before maven build. Build should happen only if codequality crosses our quality checks.
Does sonar scanner and maven are used individually or sonar scanner is integrated with maven. I know both are possible but what is the best way that we need artifacts to be created only if code passes quality checks.
How does the sonarqube tell CI system (be it azuredevops or any other system) whether to go for next steps or break if the quality check is failed.
Usually you run your full build (which contains building the jar file or in general artifacts) and the sonar analysis will be done afterwards (unit tests coverage, static code analysis etc.) and no it is not done before it's done afterwards otherwise it would not be possible to integrate results like code coverage of the unit/integration test into the sonarqube analysis.
Technically the sonar scanner can be triggered via the Maven build (it is done via a maven plugin) and often called like this: mvn verify sonar:sonar(assumed that it is configured correctly).
SonarQube has a webhook which will be called/triggered if the quality is not as expected. Most of the time the CI/CD system have a stage which will shows the result of that and makes the final result of the build "red". Also many source code hosting solutions (GitHub, GitLab, Gitea or alike) having indicators which shows that (usually) within a pull request...
Update:
If you run sonar analysis on a project without compiling the code you will get this:
$ mvn clean sonar:sonar
[INFO] JavaClasspath initialization
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.952 s
[INFO] Finished at: 2022-12-04T21:41:34+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project kata-fraction:
Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property. -> [Help 1]
[ERROR]

Maven build - surefire plugin error - File name too long

I was building project as usual with mvn clean install and following error happened:
(File name too long) -> [Help 1]
Full maven output:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:19 min
[INFO] Finished at: 2017-02-23T13:42:19+01:00
[INFO] Final Memory: 67M/544M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project union-sme-webapp: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: java.lang.RuntimeException: org.apache.maven.surefire.report.ReporterException: When writing report: /home/gondy/projects/xxxxxxx/xxxxxxxxx/webapp/target/surefire-reports/TEST-xx.xxxxx.xxxx.xxxx.webapp.service.document.generator.statics.arrangements.XxxxxxxxxxXxxxxxxXxxxxxxxxxxxXxxxxxxxXxxxxxxxxXxxx.xml (File name too long) -> [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.
I am working on Ubuntu 16.04 LTS. My colleagues are building the same project without any problem, it works even on Jenkins CI. What is the problem here? The filename is 144 chars long, which should be fine, ext has limit of 255 charactes.
The problem is, I have encrypted home directory and Ubuntu allows filename only 143 chars long:
From one of authors of eCryptfs:
Empirically, we have found that character filenames longer than 143 characters start requiring >255 characters to encrypt. So we (as eCryptfs upstream developers) typically recommend you limit your filenames to ~140 characters.
https://unix.stackexchange.com/a/32834/82647
So options basically are:
Make filename shorter by renaming methods and classes
Move your project outside encrypted directory
Remove encryption of your home directory
you can always disable file reporting via pom.xml file or console parameters
mvn clean install -Dsurefire.useFile=false -DredirectTestOutputToFile=false -DdisableXmlReport=true
Test results will be logged to console
Other way (untested by me) would be aggregating report, mentioned here maven surefire reporting plugin configuration

mvn release:prepare does not ignore file it is expected to ignore

I'm running
mvn release:prepare
which results in the following error. It complains a file was modified, which should have been ignored in the first place, since mvn put it there.
[INFO] Change the default 'svn' provider implementation to 'javasvn'.
[...]
[INFO] ignoring changes on: **/pom.xml.backup, release.properties, **/release.properties, **/pom.xml.branch, **/pom.xml.next, **/pom.xml.releaseBackup, **/pom.xml.tag
[...]
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.1:prepare (default-cli) on project company-common: Cannot prepare the release because you have local modifications :
[ERROR] [/home/ansible/branch/company-common/branches/1.0.2-JM/release.properties:unknown]
This is a commonly reported problem. Most answers suggest using relative paths for scm config. My question is how to do that? Relative to what? Here my scm for a branch:
<scm>
<connection>scm:svn:http://ipsvndev.company.com/repos/PROJ/company-common/branches/1.0.2-JM</connection>
<developerConnection>scm:svn:http://ipsvndev,company.com/repos/PROJ/company-common/branches/1.0.2-JM</developerConnection>
<url>scm:svn:http://ipsvndev.company.com/repos/PROJ/company-common/branches/1.0.2-JM</url>
</scm>

Error when trying to 'mvn clean install' Gerrit's replication plugin

This is probably a newbie question, but I'm new to Maven.
I'm trying to build Gerrit's replication plugin, "since the master branch (and thus Gerrit 2.5) no longer supports replication out of the box."
So I did clone https://gerrit.googlesource.com/plugins/replication and executed mvn clean install inside the new directory. The error message is:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building replication 1.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.google.gerrit:gerrit-plugin-api:jar:2.6-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.840s
[INFO] Finished at: Thu Apr 25 17:30:10 BRT 2013
[INFO] Final Memory: 6M/105M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project replication: Could not resolve dependencies for project com.googlesource.gerrit.plugins.replication:replication:jar:1.1-SNAPSHOT: Failure to find com.google.gerrit:gerrit-plugin-api:jar:2.6-SNAPSHOT in https://gerrit-api.commondatastorage.googleapis.com/release/ was cached in the local repository, resolution will not be
reattempted until the update interval of gerrit-api-repository has elapsed or updates are forced -> [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/DependencyResolutionException
It looks like this URL isn't valid: https://gerrit-api.commondatastorage.googleapis.com/release/ -- but like I said, I'm new to Maven so I'm not sure how to proceed. I did some research, but I don't know what I'm looking for.
Any pointer would be highly appreciated. Thanks in advance.
A couple of things -
You are missing the gerrit-plugin-api.jar. This currently isn't provided upstream, so you must build it yourself. I believe running mvn install from a Gerrit repository will package and add this jar to your system.
You don't want to run install, you just want to run package on the plugin. mvn package will put the .jar in the target/ folder, which you then copy to your plugins folder inside your Gerrit installation.
Good luck!
Like Brad mentioned, I am missing the gerrit-plugin-api.jar. Unfortunately, I was not able to build it, since the Gerrit repos seem to be facing issues lately, as mentioned in other threads (this one, for instance - from two days ago).
Anyway, below are my additional steps based on Brad's answer (hopefully this may help others):
git clone https://gerrit.googlesource.com/gerrit
cd gerrit/gerrit-plugin-api/
mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Gerrit Code Review - Plugin API 2.7-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.google.gerrit:gerrit-sshd:jar:2.7-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.google.gerrit:gerrit-httpd:jar:2.7-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.google.gerrit:gerrit-pgm:jar:2.7-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.342s
[INFO] Finished at: Fri Apr 26 10:52:54 BRT 2013
[INFO] Final Memory: 5M/105M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project gerrit-plugin-api: Could not resolve dependencies for project com.google.gerrit:gerrit-plugin-api:jar:2.7-SNAPSHOT: The following artifacts could not be resolved: com.google.gerrit:gerrit-sshd:jar:2.7-SNAPSHOT, com.google.gerrit:gerrit-httpd:jar:2.7-SNAPSHOT, com.google.gerrit:gerrit-pgm:jar:2.7-SNAPSHOT: Failure to find com.google.gerrit:gerrit-sshd:jar:2.7-SNAPSHOT in https://gerrit-maven.commondatastorage.googleapis.com was cached in the local repository, resolution will not be reattempted until the update interval of gerrit-maven has elapsed or updates are forced -> [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/DependencyResolutionException
EDIT
These are the steps that worked for me, in case someone else faces the same issue.
git clone https://gerrit.googlesource.com/gerrit
Check available 'versions'
git branch -r
git checkout -b 2.5 origin/stable-2.5
The steps didn't work on the master branch in my environment, and I'm using 2.5...
So yeah, 2.5.
cd gerrit
mvn clean install
This will rebuild the entire universe, go grab a cup of coffee. :)
.. when done
cd gerrit-plugin-api/
mvn package
This also takes some time...
If everything goes fine, you can copy the jar at the target folder, like:
cp target/<large-name>.jar ~/replication.jar
Finally install it (from ~):
ssh -p 29418 localhost gerrit plugin install -n name \ - <replication.jar
Details on how to install Gerrit plugins are here.
The thing is, now I'm getting another error, something like:
"A binding to (something) was already configured at (something)."
But that's another story / thread / post...
Thanks and good luck!
Do a mvn -P all clean install on the toplevel, not inside gerrit-plugin-api.
The fastest way to fix is is to change the pom.xml and use a version that is not a snapshot. I was trying to build the delete-project for the stable-2.6 branch and was facing the same issue. All that needs to be done is to change the Gerrit-ApiVersion:
<Gerrit-ApiType>plugin</Gerrit-ApiType>
- <Gerrit-ApiVersion>2.6-SNAPSHOT</Gerrit-ApiVersion>
+ <Gerrit-ApiVersion>2.6-rc2</Gerrit-ApiVersion>
</properties>
<name>Delete Project Gerrit Plugin</name>
Building off of #Conaaando's answer, I performed these exact steps and successfully am using the plugin. Steps courtesy of http://asheepapart.blogspot.com/2013/12/how-to-build-gerrit-replication-plugin.html
git clone --recursive https://gerrit.googlesource.com/gerrit
You need the --recursive here because the plugins are actually git submodules and won't otherwise be cloned along with your repo.
If you've already cloned, you can run git submodule init; git submodule update
cd gerrit
git checkout -b stable-2.7 origin/stable-2.7
mvn install -DskipTests=true -Dmaven.javadoc.skip=true
It's not necessary to skip the tests or generating Java Doc, but it will greatly improve your compile time and decrease the amount of memory maven uses
cd gerrit-plugin-api
mvn package -Dmaven.javadoc.skip=true
This creates the jar that will be necessary for the replication plugin to get built
cd plugins/replication
mvn package -Dmaven.javadoc.skip=true
At this point, you have compiled and packaged the replication jar! All you need to do now is register it with your Gerrit server. For simplicity, I'll pretend your gerrit server is running at gerrit.example.com. These steps copy the replication jar to your review server and then instruct the review server to install the plugin from that copied location.
scp target/replication-2.7.jar gerrit.example.com:/tmp/
ssh -p 29418 gerrit.example.com gerrit plugin install -n replication /tmp/replication-2.7.jar

How can I force a Maven clean?

I'm using Maven 3.0.3 on WinXP and running my Maven build commands through Cygwin. Occassionally, I'll be able to run a maven clean ...
mvn clean install
And I'll get errors like ...
[INFO] Deleting C:\Documents and Settings\E18538\workspace\iteration1\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.891s
[INFO] Finished at: Mon Jan 23 11:07:58 CST 2012
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project myco-productplus-web: Failed to clean project:Failed to delete C:\Documents and Settings\E18538\workspace\iteration1\target -> [Help 1]
Other than Cygwin, I'll close all other applications, but there is still a process holding something in "target". How do I figure out what that process is and then kill it? Note that when I restart my system, I can again run "mvn clean" commands.
Edit: The process that is holding onto the directory in question is "TGitCache.exe", spawned by TortoiseGit, installed on my system. I have marked the "target" directory as one to ignore, so I'm wondering if there's a way to cause this process to ignore target.
Thanks, - Dave
Run mvn -X clean to see the actual error stacktrace to figure out what's wrong. As to check what is locking the directory see unlocker.
Use mvn clean -Dmaven.clean.failOnError=false
to resolve this problem.
I am using Spring(Eclipse) to do a maven clean and already had a command line and cygwin open with target as the current directory. I closed cygwin and other console, did a maven clean on the pom.xml in Spring and it worked!
This link helped me out: http://maven.apache.org/plugins/maven-clean-plugin/faq.html

Resources