maven in Teamcity build creates maven-metadata-snapshots.xml containing NUL? - maven

What are the reasons it could create a maven-metadata-snapshots.xml filled with 'NUL' characters?
This build runs fine on local machine. Issue observed on the Team city build machine/agents.
More to this question - How is a maven-metadata-snapshots.xml generated in the entire maven build flow?
What all stages and files are created from pom.xml untill the stage of creating a maven-metadata-snapshots.xml?
My current Teamcity build breaks with -
Step 1/1: Maven: Main Build (Maven) (6m:35s)[08:46:43][Step 1/1] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project : Failed to update metadata project/maven-metadata.xml: Could not parse metadata D:\Apps\TeamCityBuildAgent2\work\m2-repo\maven-metadata-snapshots.xml: only whitespace content allowed before start tag and not \u0 (position: START_DOCUMENT seen \u0... #1:1) [08:47:27][Step 1/1] Step Maven: Main Build (Maven) failed.
How to control the encoding of this file?

This shows that the maven project metadata is corrupted.
To resolve this -
1) Login to project repo as admin
2) Create a task to recreate the project metadata.
3) The task could be a one-time run, or you could schedule it perodically if it is a persisten issue in your project environment.
This helped me!

Related

Maven - jenkins pipeline not using pom

I have a problem running a maven deploy through Jenkins. When run locally, the correct URL is contacted, but via Jenkins(in the middle of a pipeline), it does not. It also states that it is using a different plugin to do so. How do I get Jenkins to contact MY_URL like my command line does?
(I've cleaned up the output a bit)
Running the following through the command line gives me:
mvn clean deploy -DaltDeploymentRepository=nexus::default::https://MY_URL/ -DskipTests -P nexus -X -s ./settings.xml
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project MY_PROJECT: Failed to deploy artifacts: Could not transfer artifact from/to nexus (https://MY_URL): Failed to transfer file 20200217.092316-15.jar with status code 401 -> [Help 1]
This is what I want (I'm waiting on credentials - but it is hitting the correct URL)
Running via Jenkins gives me:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy (default-deploy) on project : Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
I have done a "diff" on the pom files in use by jenkins and locally and they are identical; likewise with the settings.xml I suspect this is a plugin problem but do not know where to go with it.
Items I have tried:
mvn clean beforehand
reinstalling mvn
echoing the settings.xml and pom.xml into the jenkins output
Specifying altDeploymentRepository in the settings.xml and/or
commandline
Specifying altDeploymentRepository using the -Dproperties= flag
Combinations of altDeploymentRepository, altDeploymentDirectory,
altSnapshotDeploymentRepository
Endless research
Hopeful reruns
Banging head on desk
Your Jenkins runs the org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy goal.
It is either specified in the POM or given on command line. So first of all, check whether the nexus-staging-maven-plugin is configured in your POM or in one of the parent POMs. If so, check if it run conditionally or is part of a profile.
Secondly, look at the command line call in Jenkins and see if it is exactly the same as the one you ran locally.
The third possibility is that you run a Jenkins plugin from Sonatype that implicitly tries to deploy artifacts. So watch out for Sonatype specific Jenkins plugins.
One of the three strategies should lead to the source of the problem.

project module are getting skipped in night build configuration

Kindly note: "I have edited this question"
I am observing a very strange situation. I have 2 jobs configured in Jenkins having same configuration except that one of them is continuous build and another is nightly build [ poll scm configured #midnight] with Sonarqube configuration to generate report.
Both builds have same Repository URL and Both of them are having build result success. But in continuous build, every modules is analysed and then getting success. whereas in nightly build, modules are skipped.
what my question is same build is running fine for continuous build and not for nightly. so what could be cause of this ?
Earlier i was using -DskipTests which was analysing all module and getting successful in continuous build.. but was skipping in nightly build.
so i refered this link Maven skip tests and added -Dmaven.test.skip=true in maven goals.. and now some of the modules are analysed and getting success. But one fo the module got failed and due to which other modules got skipped. below is the error log
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
(default-test) on project ASData: There are test failures.
Note: I am using maven 3.3.1 version and SonarQube 5.1
I am still not allowed to add comments so I will ask here.
Where do you keep the modules and can you guarantee that noone will severe the connection between your build and the storage of modules?

How to release Maven project using Jenkins

When I am trying to release a Maven project using Jenkins, I am getting an error like this:
Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5:prepare (default-cli) on project maven-plugin: You don't have a SNAPSHOT project in the reactor projects list.
The error message means that the project (or one of its submodules) is not a SNAPSHOT project, i.e. it's version is not [version]-SNAPSHOT but only [version].
You cannot release a project that is not a SNAPSHOT project so you need to change the version of your pom.xml to include -SNAPSHOT.

tycho-p2-publisher-plugin fails on build with maven-release-plugin

I am using the tycho-p2-publisher-plugin in order to create a p2 site which can be uploaded to Nexus as described at Tool for managing/hosting own p2 repositories? - it aimed to be a work-around for the fact that Nexus does not seem to support hosted p2 repositories.
My problem is: the p2 artifacts are created fine and are even uploaded to Nexus whenever I do a snapshot build. However, when I try a release build, the build fails because of
[INFO] INFORMATION: I/O exception (java.io.FileNotFoundException) caught when processing request: /home/hudson/jobs/jobname/workspace/our.component.build/target/checkout/our.component.repository/target/p2content.xml
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project our.component.repository: Failed to deploy artifacts: Could not transfer artifact our.component:our.component.repository:xml:p2metadata:1.1.18 from/to releases (http://192.168.205.205:8081/nexus/content/repositories/releases): /home/hudson/jobs/jobname/workspace/thirdparty/our.component.build/target/checkout/our.component.repository/target/p2content.xml (Datei oder Verzeichnis nicht gefunden) -> [Help 1]
p2content.xml is not found, simply because it's not there. The question is, should it be there?
I am using the maven release plugin, and as far as I understand, during the release build process, all components are prepared, then checked in and tagged with the release version. After that, they are checked back out from the tag, and then the build is started. As obviously the release build is run for the checkout folder (as seen above: .../target/checkout/...), the problem seems to be that p2context.xml is created by the tycho-p2-publisher-plugin during the build, but not checked in, while later it is expected to appear in the checkout folder. I would guess that Maven should not expect the file there and try to deploy it to Nexus, but I fail to understand why is it expected to be there? And what's the right approach to cure my release build?

SonarQube scan failing with "is already part of project XXX error is already part of project"

Recently I upgraded sonarqube from 4.0 to 4.3.3. Post upgrade when I try to run the maven build I am getting the error:
Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project xxx on project yyy Module "abc.def.xyz" is already part of project of other project.
The issue is we scan on multiple branches so we will have modules with the same name.
Is there a way to turn off this validation?
Assume you have multiple modules Maven project with below structure:
com.company:project
com.company:project-module1
com.company:project-module2
In your java source code, now "com.company:project" renamed to "com.company:myProject", so new java source strucutre becomes:
com.company:myProject
com.company:project-module1
com.company:project-module2
When you build new source and push analysis data to Sonar, it prompt:
[ERROR] Failed to execute goal
org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar
(default-cli) on project myProject: Module
"com.company:project-module1" is already part of project
"com.company:project" -> [Help 1]
This error is because the "com.company:project-module1" already executed and registered into Sonar before and now it belongs to "com.company:project" project whihc no longer exist in your source code anymore.
Solution:
In Sonar project configuration --> Update key, change the project "com.company:project" key from "com.company:project" to "com.company:myProject", rerun Maven build and push to Sonar, issue will solve.

Resources