Maven: Trying to Deploy with credentials in settings.xml file - maven

This seemed to be working last week and now it doesn't.
We use Artifactory as our Maven repository.
I am deploying a jar and pom using the deploy:deploy-file goal
Our Artifactory repository requires authentication to deploy.
I can deploy to the repository by embedding my credentials in the server URL on the command line:
$ mvn deploy:deploy-file \
-Durl=http://deployer:swordfish#repo.veggiecorp.com/artifactory/ext-release-local \
-Dfile=crypto.jar \
-DpomFile=pom.xml \
-Did=VeggieCorp
yadda...yadda...yadda...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.962s
[INFO] Finished at: Mon Aug 20 10:06:04 CDT 2012
[INFO] Final Memory: 4M/118M
[INFO] ------------------------------------------------------------------------
However, that whole deployment gets logged and my credentials would be visible in the log. Therefore, I want to be able to deploy without my credentials on the command line. To do that, I have a $HOME/.m2/settings.xml file:
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.veggiecorp.com</host>
<port>3128</port>
<nonProxyHosts>*.veggiecorp.com</nonProxyHosts>
</proxy>
</proxies>
<servers>
<server>
<id>VeggieCorp</id>
<username>deployer</username>
<password>swordfish</password>
</server>
</servers>
<profiles>
<profile>
<id>VeggieCorp</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>VeggieCorp</id>
<name>VeggieCorp's Maven Repository</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<url>http://repo.veggiecorp.com/artifactory/ext-release-local</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>VeggieCorp</activeProfile>
</activeProfiles>
</settings>
Now, I'll try deploying again, but without putting the user name and password in the URL:
$ mvn deploy:deploy-file \
-Durl=http://repo.veggiecorp.com/artifactory/ext-release-local \
-Dfile=crypto.jar \
-DpomFile=pom.xml \
-Did=VeggieCorp
yadda...yadda...yadda
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.751s
[INFO] Finished at: Mon Aug 20 10:17:15 CDT 2012
[INFO] Final Memory: 4M/119M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy- file (default-cli) on project crypto:
Failed to deploy artifacts: Could not transfer artifact
com.veggiecorp:crypto:jar:2.0.0 from/to remote-repository
(http://mvn.veggiecorp.com/artifactory/ext-release-local):
Failed to transfer file:
http://mvn.veggiecorp.com/artifactory/ext-release-local/com/veggiecorp/crypto/2.0.0/crypto-2.0.0.jar.
Return code is: 401, ReasonPhrase:Unauthorized. -> [Help 1]
(I've reformatted the output to make it easier to see. I'm getting a 401 "Unauthorized" error)
So, what am I doing wrong? Why can't I use my .settings.xml file to do my credentials? The proxy part does work because it can download the needed plugins from the main Maven repository.

You need to provide the repositoryId=VeggieCorp (not id) property so that maven knows from which <server> configuration it has to read the credentials.
$ mvn deploy:deploy-file \
-Durl=http://repo.veggiecorp.com/artifactory/ext-release-local \
-Dfile=crypto.jar \
-DpomFile=pom.xml \
-DrepositoryId=VeggieCorp
See http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html

You can also specify your snapshot repository id in distributionManagement
<distributionManagement>
<repository>
<id>releases</id>
<url>${env.MAVEN_RELEASE_REPOSITORY_URL}</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>${env.MAVEN_SNAPSHOT_REPOSITORY_URL}</url>
</snapshotRepository>
</distributionManagement>
the ids here should match ones in servers

Related

Unable to get *.tar.gz files from Nexus Repository

I'm tring to install Maven Wrapper and get "Error installing the Maven Wrapper.: Server returned HTTP response code: 401" from my Nexus Repository.
To reproduce the error I can just remove a local cache of Maven Wrapper and try to install it to an empty folder:
rm -R ~/.m2/repository/io/takari/maven-wrapper/0.5.6/
mvn -N io.takari:maven:wrapper -Dmaven=3.8.4
The output:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven:0.7.7:wrapper (default-cli) # standalone-pom ---
Downloading from nexus: http://localhost:8081/repository/maven-public/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.pom
Downloaded from nexus: http://localhost:8081/repository/maven-public/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.pom (2.4 kB at 15 kB/s)
Downloading from nexus: http://localhost:8081/repository/maven-public/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
Downloaded from nexus: http://localhost:8081/repository/maven-public/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar (51 kB at 1.5 MB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.103 s
[INFO] Finished at: 2022-03-21T10:45:51+05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.takari:maven:0.7.7:wrapper (default-cli) on project standalone-pom: Error installing the Maven Wrapper.: Server returned HTTP response code: 401 for URL: http://localhost:8081/repository/maven-public/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.tar.gz -> [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/MojoExecutionException
pom and jar files are downloaded just fine. The problem is with tar.gz file only.
Here is my settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings
xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>1</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<url>http://localhost:8081/repository/maven-public</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
The URL http://localhost:8081/repository/maven-public/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.tar.gz?describe is retrived just fine in a browser:
Code 200
Content-Type application/x-gzip
Size 51848
Error 401 is unauthorize error
Did you try to put an autologin config file in your user's home directory already?
Example: /Users/my_username/.netrc
machine nexus.somewhere.com
login correct_user
password correct_password
You also need to ensure the account is available and have valid permission to target lib

mvn install package from GitHub package registry

I've followed steps given in this document to deploy a package on GitHub package registry, I'm able to successfully deploy a package. That can be seen here.
Now I'm trying to install this as a dependency in another project. As given in the above link I added this dependency in my pom file.
<dependency>
<groupId>com.github.ashishchopra/github_package_registry</groupId>
<artifactId>group-upload.artifct-upload</artifactId>
<version>0.0.1</version>
</dependency>
Which obviously throws me this error:
[ERROR] 'dependencies.dependency.groupId' for com.github.ashishchopra/github_package_registry:group-upload.artifct-upload:jar with value 'com.github.ashishchopra/github_package_registry' does not match a valid id pattern.
Now I remove the part before / in the groupId and made dependency like this:
<dependency>
<groupId>github_package_registry</groupId>
<artifactId>group-upload.artifct-upload</artifactId>
<version>0.0.1</version>
</dependency>
Now I'm getting this error:
Downloading: https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/group-upload.artifct-upload-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.275 s
[INFO] Finished at: 2019-10-10T19:47:42+05:30
[INFO] Final Memory: 18M/67M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project artifct-download: Could not resolve dependencies
for project group-download:artifct-download:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at github_package_registry:group-upload.artifct-upload:jar:0.0.1: Failed to read artifact descriptor for github_package_registry:group-upload.artifct-upload:jar:0.0.1: Could not transfer artifact github_package_registry:group-upload.artifct-upload:pom:0.0.1 from/to github (https://maven.pkg.github.com/ashishchopra): Failed to transfer file: https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/group-upload.artifct-upload-0.0.1.pom. Return code is: 400 , ReasonPhrase:Bad Request. -> [Help 1]
I also tried removing groupId. part from artifactId in dependency and made it like this:
<dependency>
<groupId>github_package_registry</groupId>
<artifactId>artifct-upload</artifactId>
<version>0.0.1</version>
</dependency>
This time I'm getting this error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.417 s
[INFO] Finished at: 2019-10-10T19:52:08+05:30
[INFO] Final Memory: 18M/67M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project artifct-download: Could not resolve dependencies for project group-download:artifct-download:jar:0.0.1-SNAPSHOT: Could not find artifact github_package_registry:artifct-upload:jar:0.0.1 in central (https://repo1.maven.org/maven2) ->
[Help 1]
So with no combination, it seems to be working.
Content of my ~/.m2/settings.yml file:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>github</id>
<name>GitHub ashishchopra Apache Maven Packages</name>
<url>https://maven.pkg.github.com/ashishchopra</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>ashishchopra</username>
<password>XXXX</password>
</server>
</servers>
These are direct steps from their documentation, nothing fancy, still, I'm not able to make it work.
In-fact pom and jar files are present at this link
https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/artifct-upload-0.0.1.pom
https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/artifct-upload-0.0.1.jar
As per the documentation you pointed to, the URL of the maven repository should include the name of your GitHub repository, i.e. github_package_registry. So that’s what you need in your settings.xml:
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/ashishchopra/github_package_registry</url>
</repository>
</repositories>
And in your pom.xml, just use the dependency described in your GitHub Packages page:
<dependency>
<groupId>group-upload</groupId>
<artifactId>artifct-upload</artifactId>
<version>0.0.1</version>
</dependency>
for some reason is not looking in the right repo, try to put this at the top of your settings.yml
<repository>
<id>github</id>
<name>GitHub ashishchopra Apache Maven Packages</name>
<url>https://maven.pkg.github.com/ashishchopra</url>
</repository>

maven deploy does not work for releases

Hi I am a beginner for maven build tool. I built a simple maven JavaEE project and I tried to build it remote nexus repository. But i can deploy successfully only for snapshots. Releases deploying gives 400 bad request error.
here is my Setting.xml configuration
<servers>
<server>
<id>****</id>
<username>****</username>
<password>****</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://******:8081/nexus/content/groups/net.******.timetrack/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>*****</id>
<url>http://******:8081/nexus/content/groups/net.*******.timetrack/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>******</id>
<url>http://******:8081/nexus/content/groups/net.******.timetrack/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
and here is my pom.xml's distribution management
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>*****</id>
<name>******</name>
<url>http://*******:8081/nexus/content/groups/net.******.timetrack/</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>*****</id>
<name>***** Snapshots</name>
<url>http://******:8081/nexus/content/repositories/snapshots/</url>
<layout>legacy</layout>
</snapshotRepository>
</distributionManagement>
If I run mvn clean deploy with (for a snapshot)
<groupId>net.*****.*****</groupId>
<artifactId>*****-**-****</artifactId>
<version>1.4-SNAPSHOT</version>
<packaging>war</packaging>
then successfully deploy in to nexus repository snapshot directory.
If it I run mvn clean deploy with (for a release)
<groupId>net.*****.****</groupId>
<artifactId>****-***-*****</artifactId>
<version>1.4.1</version>
<packaging>war</packaging>
then it gives 400-bad request error
Here is the log for the error
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) # ****-****-***** ---
[INFO] Packaging webapp
[INFO] Assembling webapp [*****-time-tracker] in [/home/dilanka/Projects/time_tracker/samples/GitLab/****/***-time-tracker/target/*****-time-tracker-1.4]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/dilanka/Projects/time_tracker/samples/GitLab/*****/****-time-tracker/src/main/webapp]
[INFO] Webapp assembled in [115 msecs]
[INFO] Building war: /home/dilanka/Projects/time_tracker/samples/GitLab/TimeTracker/*****-time-tracker/target/****-time-tracker-1.4.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # ****-time-tracker ---
[INFO] Installing /home/dilanka/Projects/time_tracker/samples/GitLab/TimeTracker/****-time-tracker/target/****-time-tracker-1.4.war to /home/dilanka/maven3-repo/net/*****/timetrack/****-time-tracker/1.4/****-time-tracker-1.4.war
[INFO] Installing /home/dilanka/Projects/time_tracker/samples/GitLab/TimeTracker/****-time-tracker/pom.xml to /home/dilanka/maven3-repo/net/****/timetrack/****-time-tracker/1.4/****-time-tracker-1.4.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) # ****-time-tracker ---
Uploading: http://*****:8081/nexus/content/groups/net.*****.timetrack/net/****s/timetrack/***-time-tracker/1.4/****-time-tracker-1.4.war
Uploading: http://*****:8081/nexus/content/groups/net.****.timetrack/net/****/timetrack/****-time-tracker/1.4/****-time-tracker-1.4.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.790 s
[INFO] Finished at: 2016-01-08T15:28:08+05:30
[INFO] Final Memory: 32M/252M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project ****-time-tracker: Failed to deploy artifacts: Could not transfer artifact net.****.timetrack:*****-time-tracker:war:1.4 from/to ***** (http://*****:8081/nexus/content/groups/net.****.timetrack/): Failed to transfer file: http://*****:8081/nexus/content/groups/net.****.timetrack/net/*****/timetrack/*****-time-tracker/1.4/****-time-tracker-1.4.war. Return code is: 400, ReasonPhrase: Bad Request. -> [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/MojoExecutionException
If any body please help me to solve this problem.
Thanks.
You can deploy a release version of a given artifact exactly once to a given Nexus instance.
If the same version already exists in your Nexus, you'll get an error like the one you're seeing.
<url>http://*******:8081/nexus/content/groups/net.****.timetrack/</url>
You can't deploy into a group repository, change this URL to be the URL of a hosted release repository.

maven release:prepare with artifactory deploy substep fails

after researching now for days and close to suicidal tendencies here my problem and really really hope that i was too stupid to find the problem by myself ....
setup: windows7 / maven 3.2.3 / jdk 1.7.0_60 (64bit) / artifactory 3.5.0
Problem:
- mvn clean install deploy --> works
- mvn release:prepare --> works
- mvn release:perform fails in substep deploy (which works standalone as mentioned before)
- POM.XML and settings.xml (for testing i took the pregenerated one from artifactory) for me. but i attached them further down....
thnx in advance for ANY help!
cheers
j.
log:
.....
[INFO] [INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) # apps.hr ---
[INFO] Uploading: http://vm-local-repo.fernbach-lu.dom:8081/artifactory/libs-release-local/com/fernbach/apps.hr/0.1.4/apps.hr-0.1.4.war
[INFO] 2/75918 KB
[INFO] 4/75918 KB
[INFO] 6/75918 KB
[INFO] 8/75918 KB
....
[INFO] 60/75918 KB
[INFO] Apr 01, 2015 4:56:30 PM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
[INFO] 62/75918 KB
[INFO] INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
[INFO] 64/75918 KB
[INFO] Apr 01, 2015 4:56:30 PM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
[INFO] INFO: Retrying request
[INFO] 66/75918 KB
[INFO] Apr 01, 2015 4:56:30 PM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
[INFO] 68/75918 KB
.....
.....
[INFO] 390/75918 KB
[INFO] 392/75918 KB
[INFO]
[INFO] Uploading: http://vm-local-repo.fernbach-lu.dom:8081/artifactory/libs-release-local/com/fernbach/apps.hr/0.1.4/apps.hr-0.1.4.pom
[INFO] 2/2 KB
[INFO]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 23.043 s
[INFO] [INFO] Finished at: 2015-04-01T16:56:30+02:00
[INFO] [INFO] Final Memory: 47M/366M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project apps.hr: Failed to
deploy artifacts: Could not transfer artifact com.fernbach:apps.hr:war:0.1.4 from/to fs-releases (http://vm-local-repo.fernbach-lu.dom:8081
/artifactory/libs-release-local): Connection reset by peer: socket write error -> [Help 1]
...
SETTINGS.XML
?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<localRepository>d:/fr4/maven/repo</localRepository>
<servers>
<server>
<username>jus</username>
<password>AP6XtRyuPNMVbXfnzP9BopSDp66</password>
<id>central</id>
</server>
<server>
<username>jus</username>
<password>AP6XtRyuPNMVbXfnzP9BopSDp66</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://vm-local-repo:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://vm-local-repo:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://vm-local-repo:8081/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://vm-local-repo:8081/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
POM.XML
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<parent>
<groupId>com.fernbach</groupId>
<artifactId>fernbach.parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>apps.hr</artifactId>
<version>0.1.5-SNAPSHOT</version>
<packaging>war</packaging>
<name>HR</name>
<properties>
<foundation.version>1.0.0</foundation.version>
</properties>
<dependencies>
<dependency>
<groupId>com.fernbach</groupId>
<artifactId>foundation.core</artifactId>
<version>${foundation.version}</version>
</dependency>
<dependency>
<groupId>com.fernbach</groupId>
<artifactId>foundation.web</artifactId>
<version>${foundation.version}</version>
</dependency>
</dependencies>
<scm>
<developerConnection>scm:svn:http://vm-uranus1.fernbach-lu.dom/svn/fernbach-R4/apps/hr/branches/BRANCH_0.1.1</developerConnection>
<url>scm:svn:http://vm-uranus1.fernbach-lu.dom/svn/fernbach-R4/apps/hr/branches/BRANCH_0.1.1</url>
</scm>
</project>
I finally found a solution in a comment of a Maven Bug that had been reported for version 3.2.3.
Here's the bug: https://issues.apache.org/jira/browse/MNG-5684
The problem is the maven-source-plugin which is used to attach source jars to the project. More exactly it's the no-fork goals that cause this behavior. Using these goals the deploy plugin tries to upload the source jars twice which fails due to repository restrictions.
The solution can either be omitting the source-plugin (but then you won't have attached sources anymore) or using the forked goals (jar and test-jar) instead.
I now use the forked goals with maven 3.3.3 and I'm able to release projects again.

Why is Maven uploading incorrectly snapshots to release repository?

I'm trying to use the maven-deploy-plugin to upload releases and snapshots into a Nexus repository. However I run across this error
[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from nexus
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.jar
56K uploaded (edr-app-1.0.4-20120605.140242-20.jar)
[INFO] Uploading project information for edr-app 1.0.4-20120605.140242-20
[INFO] Retrieving previous metadata from nexus
[INFO] Uploading repository metadata for: 'artifact info.afilias.edr:edr-app'
[INFO] Retrieving previous metadata from nexus
[INFO] Uploading repository metadata for: 'snapshot info.afilias.edr:edr-app:1.0.4-SNAPSHOT'
[INFO] Retrieving previous build number from nexus
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz
4286K uploaded (edr-app-1.0.4-20120605.140242-20.tar.gz)
[INFO] [deploy:deploy-file {execution: default}]
Uploading: http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4/edr-app-1.0.4.tar.gz
89530K uploaded (edr-app-1.0.4.tar.gz)
[INFO] Uploading project information for edr-app 1.0.4
[INFO] Retrieving previous metadata from remote-repository
[INFO] Uploading repository metadata for: 'artifact info.afilias.edr:edr-app'
[INFO] Retrieving previous build number from remote-repository
[INFO] repository metadata for: 'snapshot info.afilias.edr:edr-app:1.0.4-SNAPSHOT' could not be found on repository: remote-repository, so will be created
Uploading: http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying attached artifact /home/mren/trunk2/target/edr-app-1.0.4-SNAPSHOT.tar.gz: Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz. Return code is: 400
Here's my configuration in the pom.xml:
<project>
...
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
...
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>target/edr-install-1.0.4-${revision}.tar.gz</file>
<url>${project.distributionManagement.repository.url}</url>
<packaging>tar.gz</packaging>
<artifactId>artifactId</artifactId>
<groupId>groupId</groupId>
<version>1.0.4-${revision}</version>
</configuration>
</execution>
</executions>
</plugin>
...
</build>
...
</project>
And from my settings.xml file:
<settings>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
I'm sure this configuration worked at one point, but now it's spitting out an error. Not sure what is wrong.
And the nexus log tells me that it's trying to upload a snapshot into a release repository
jvm 1 | 2012-06-04 14:16:31 INFO [tp1706427008-35] - org.sonatype.nexus.proxy.maven.maven2.M2Repository - Storing of item releases:/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120604.181534-1.tar.gz is forbidden by Maven Repository policy. Because releases is a RELEASE repository
jvm 1 | 2012-06-04 14:16:31 ERROR [tp1706427008-35] - org.sonatype.nexus.rest.ContentPlexusResource - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120604.181534-1.tar.gz": Storing of item releases:/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120604.181534-1.tar.gz is forbidden by Maven Repository policy. Because releases is a RELEASE repository
Your settings.xml is incorrect. Please configure Maven to use Nexus correctly following the book chapter. Specifically use the mirror settings and the url in there and not specific urls for repository and pluginRepository.
It interferes with your correct Maven pom and ends up trying to deploy a snapshot into a release repository, which is incorrect.
In addition it will be important that you use the correct goal/command. Do not use deploy-file goal directly or so.
Just run the command
mvn clean deploy
on the build.
And another clarification. Maven will deploy whatever is determined from the version. If it ends in -SNASPHOT is is a development version and be published to the snapshot repo (and will allow redeploys incrementing the version number) and if it does not it is considered a release and will deploy to the release repo. A project can not be a snapshot and a release at the same time. It is one or the other.
Do not mix the two concepts of release and snapshot!
And in terms of getting additional artifacts deployed I would either pull them out into a separate project/module if they are not associated or if they are look into the attach-artifact goal of the build helper plugin.
It's because you are telling Maven to deploy a file that looks like a snapshot. Take a look at your deploy:deploy-file config. The ${revision} has the same format as a snapshot so Nexus nacks it:
target/edr-install-1.0.4-${revision}.tar.gz becomes: info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz
For reference the regex that Maven and Nexus use to decide what a snapshot is/is not is covered here:
http://www.sonatype.com/people/2008/05/maven-code-how-to-detect-if-you-have-a-snapshot-version/
The other thing I would recommend is don't use deploy:deploy-file, instead use the buildhelper:attach to attach this tar.gz and then the file will be named appropriately, avoiding all of the hacking you did with the revision.

Resources