Create release without specifying repository - maven

In my Maven project, I am trying to make a release, but for now I don't want to deploy it anywhere(I will do that later).
I would like the JAR file or whatever is generated because of the release to remain on my local machine, without being deployed anywhere.
I am running this:
mvn release:prepare
mvn release:perform
The problem is that on the second line I am getting this error:
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-project: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
What is this about?
I don't have any distributionManagement tag in my project and if I would have one, I wouldn't know what to do with it.

You have 2 options:
set the value for the goals parameter of the maven-release-plugin to install
if you never want to deploy to a remote repository, set the skip parameter of the maven-deploy-plugin to true.

Add this to the code:
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

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.

cannot deploy zip to Nexus

I'm trying to check a zip file (created by an external process) into Nexus using mvn deploy:deploy-file.
When I run from the command line (Win), everything works and I can see the pom and zip in my snapshot repo. However If I use a maven job in Jenkins to do the same I'm getting the following error :
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unknown packaging: zip # line 6, column 13
pom looks like :
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>testApp</artifactId>
<version>1.0.0.0-SNAPSHOT</version>
<packaging>zip</packaging>
</project>
mvn command is :
mvn deploy:deploy-file -DpomFile=d:\testApp.pom -Dfile=d:\testapp.zip
-DrepositoryId=snapshots
-Durl=http://localhost:8081/nexus/content/repositories/snapshots
If I was using the wrong packaging, why does it work for one and not the other ?
This page describes the <packaging> tag: http://maven.apache.org/pom.html#Maven_Coordinates
It says, and I quote:
The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par.
Additional plugins can add additional packaging types when they modify the lifecycle.
This information applies to the tag in the pom.
Possible solution: If you comment out or remove the <packaging>zip</packaging> it will stop failing with an error message.
This means when you can use the command with one more -D option
mvn deploy:deploy-file ... -Dfile=somefile.zip -Dpackaging=zip
to publish a file to a maven repository like Nexus or Artifactory. Maven will not complain because its only checking the tag for validity.
However, if you are doing anything else with Maven and that anything requires you to set the packaging type, you will need to find another solution.

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>

Maven and Multiple Goals

I'm attempting to use the Grails Maven plugin to build a war file. There's a known problem with the plugin in that it does not resolve range dependencies, and my project pom file must contain range dependencies.
The dependency is specified like this:
<dependency>
<groupId>mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>[0.0.0,999.999.999)</version>
</dependency>
The error message is like this:
[ERROR] Failed to execute goal
org.grails:grails-maven-plugin:2.2.1:clean (default-clean) on project
sdm: Failed to create classpath for Grails execution. Encountered
problems resolving dependencies of the executable in preparation for
its execution. Error resolving project artifact: Could not transfer
artifact mygroup.myartifact:pom:[0.0.0,999.999.999) from/to myRepo
(https://maven.mydomain/nexus/content/groups/myRepo):
IllegalArgumentException for project
mygroup.myartifact:pom:[0.0.0,999.999.999): Illegal character in path
at index 89:
https://maven.mydomain/nexus/content/groups/myRepo/mygroup/myartifact/[0.0.0,999.999.999)/myartifact-[0.0.0,999.999.999).pom
-> [Help 1]
As you can see, the range dependency is not being resolved, and a literal version "[0.0.0,999.999.999)" is being looked for.
To work around the problem, I can use the Maven version plugin and do this:
mvn versions:resolve-ranges [replaces range deps in pom file with actual versions]
mvn grails:war [builds war based on actual versions in newly modified pom file]
mvn versions:revert [reverts pom file to original state]
BUT here's my problem: if I combine these goals into one Maven command:
mvn versions:resolve-ranges grails:war versions:revert
the grails:war fails with the error I described above - it seems to be seeing the pom file in its initial state (with the range dependencies), even though the versions plugin has updated the pom file with actual version numbers. After the failure, the pom file has this:
<dependency>
<groupId>mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>2.1.15</version>
</dependency>
So my question is - why does the second goal (grails:war) see the pom file as it was at the start of the whole chain of goals, not as it is when the goal runs? How can I make the second goal (grails:war) see the pom file as it stands after completion of the first goal (versions:resolve-ranges)?

maven error: The desired archetype does not exist (org.phpmaven:php5-web-archetype:2.0-SNAPSHOT)

I am trying to create php project using maven by tying below command:
sudo mvn archetype:generate -DarchetypeGroupId=org.phpmaven
-DarchetypeArtifactId=php5-web-archetype -DarchetypeVersion=2.0-SNAPSHOT
-DgroupId=org.sample -DartifactId=my-app -Dversion=0.0.1-SNAPSHOT
but it gives me error:
Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli)
on project standalone-pom: The desired archetype does not exist (org.phpmaven:php5-web-archetype:2.0-SNAPSHOT) -> [Help 1]
Apparently you're trying to follow these instructions. If you do, you should also do the preparation steps that have been listed.
Doing that you're relying on a snapshot archetype, and those do not exist in default repositories, so you have to configure php-maven snapshot repository.
After doing that,
Confirm your settings.xml location (in the comments you indicated you had that in the wrong folder)
try with
mvn archetype:generate -DarchetypeGroupId=org.phpmaven.sites
-DarchetypeArtifactId=php5-web-archetype -DarchetypeVersion=2.0.0-beta-1
-DgroupId=org.sample -DartifactId=my-app -Dversion=0.0.1-SNAPSHOT
Since you can see from the repo that that archetype version should be in place. Note the different archetypeversion and different archetypegroupid!

Resources