I am facing an issue when trying to publish an artifact in private gitlab repository. I am using maven and I authenticated using personal access token. When I run mvn deploy -s ~/.m2/settings.xml I get the following error Failed to deploy artifacts: Could not transfer artifact ... 401 Unauthorized
My settings.xml file looks like this.
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>personal-token</name>
<value>mytoken</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
I've also tried changing it to
<servers>
<server>
<id>gitlab-maven</id>
<username>username</username>
<password>pass</password>
</server>
</servers>
but that didn't help. And here is my pom publishing part
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.mycompany.com/api/v4/projects/92/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.mycompany.com/api/v4/projects/92/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.mycompany.com/api/v4/projects/92/packages/maven</url>
</snapshotRepository>
</distributionManagement>
Is there anything that I'm missing? Thank you in advance.
Fixed this by changing property in the settings file to Private-Token (I was using actual name of the token previously)
I had the same problem but for a different reason.
my idea (intellij with built in maven plugin) was using different settings file (C:\Users\YOUR_USER_NAME\.m2\settings.xml) from the one i configured the server (local maven installation on a different path).
to fix this go to: File -> Settings (on windows Ctrl + Alt + s) -> Build, Execution, Deployment -> Build Tools -> Maven -> User settings file.
mark the check box for Override and direct to the correct path.
hopefully it will save someone's time...
In case this might help someone:
Once you reach the "mvn deploy" step in the gitlab docs and find yourself struggling with 401 Unauthorized error, running the deploy command with -s or --settings flag like so:
mvn deploy -s settings.xml (the argument to the -s flag is the path to your project settings.xml file)
Solves the issue (at least for me) by using the user specified settings file instead of the default one stored in .m2 folder.
(I found solution in this video)
Related
This is the way it currently works, and it's the Maven Deploy Plugin Usage
pom.xml
[...]
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>MyCo Internal Repository</name>
<url>Host to Company Repository</url>
</repository>
</distributionManagement>
[...]
settings.xml
[...]
<server>
<id>internal.repo</id>
<username>someUser</username>
<password>somePassword</password>
</server>
[...]
and what I'm trying to achieve is finding a way in which the username and password are typed in at the command line. to achieve mvn deploy -someUser -somePassword
The settings.xml is considered personal, so for that reason the username+password are stored in the (user-)settings.xml. So in general there's no reason to pass them as argument. (btw, passwords can be stored encrypted here) The maven-deploy-plugin has no option to pass them via commandline. However, I've seen hacks like:
<username>${internal.repo.username}</username>
And now you can do -Dinternal.repo.username=someUser
I'll lay out here the full solution, but basically Robert Scholte's solution works brilliant.
In your ~/.m2/settings.xml you should have the following
<settings>
<servers>
<server>
<id>${repo.id}</id>
<username>${repo.login}</username>
<password>${repo.pwd}</password>
</server>
</servers>
</settings>
and then you just
mvn -Drepo.id=myRepo -Drepo.login=someUser -Drepo.pwd=somePassword clean install
You can even use your environment variable (if you are doing that on the remote server/container, for example):
mvn -Drepo.id=$REPO_ID -Drepo.login=$REPO_LOGIN -Drepo.pwd=$REPO_PWD clean install
This also works:
<server>
<id>${repo.id}</id>
<username>${repo.username}</username>
<password>${repo.password}</password>
</server>
I am working on getting Anonimatron available as libary in the central Maven Repository. In order to do that I followed the documentation in the sonatype documentation. The nexus staging plugin gives me a 401 error when running mvn deploy and I can't figure out why because it does not tell me what is going on.
I have a working account at oss.sonatype.org, and I have created a user access token there. The access token is stored in the servers section of my maven ~/.m2/settings.xml like so (token removed for reasons):
<servers>
<server>
<id>ossrh</id>
<username>USER_TOKEN</username>
<password>USER_PASSPHRASE</password>
</server>
</servers>
Then, in my maven https://github.com/realrolfje/anonimatron/blob/feature/anonimatron-as-library/pom.xml file I added the nexus staging plugin:
<distributionManagement>
<snapshotRepository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-release</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>
[...]
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
When I run mvn deploy, I get the error:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7:deploy (injected-nexus-deploy) on project anonimatron: Failed to deploy artifacts: Could not transfer artifact com.rolfje.anonimatron:anonimatron:jar:javadoc:1.9.3-20180512.204932-1 from/to sonatype-snapshots (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/rolfje/anonimatron/anonimatron/1.9.3-SNAPSHOT/anonimatron-1.9.3-20180512.204932-1-javadoc.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
To check wether my token is indeed valid, I tried uploading with curl:
curl -u USER_TOKEN:USER_PASSPHRASE \
https://oss.sonatype.org/content/repositories/snapshots/com/rolfje/anonimatron/anonimatron/1.9.3-SNAPSHOT/anonimatron-1.9.3-20180512.093802-1-javadoc.jar \
--request PUT --data target/anonimatron-1.9.3-SNAPSHOT.jar
This succeeds and I can see the uploaded jar appear in the Nexus Repository Manager.
I have executed the same steps as in this question but since I have not uploaded anything yet, version numbers can not collide, although I did do a manual javadoc upload at the end. Since that is a snapshot, and it worked, I think my problem is with the nexus-staging-maven-plugin.
What I am searching for is a way to debug the nexus-staging-maven-plugin so that I know why it is failing. It does not tell me which credentials it is using, wether it loaded those from the settings.xml file, and what exact steps it is taking, even if I run mvn with -e and -X flags.
Executing a deploy with the standard maven-deploy plugin, as #khmarbaise mentioned, did seem to work. I reported this problem to sonatype as part of issues
OSSRH-39766 and OSSRH-39777.
Joel regenerated my permissions and now the nexus release plugin seems to be working. Note that this could also be caused by the maven-deploy which might have "primed" something.
All in all, the nexus release plugin could do with some improvements on the logging, particularly:
What profile is used to execute the steps
What step (exactly) is being executed
If there is a 401, tell which userid was used to execute that step and from which environment that was fetched (command line, settings.xml, etc).
I see some people struggling with the nexus plugin, while the plugin should actually make life easier.
Thanks to SonaType for the fast and helpful responses!
Add the following in your ~/.m2/settings.xml file:
<servers>
<server>
<id>ossrh</id>
<username>{YOUR_JIRA_USERNAME}</username>
<password>{YOUR_JIRA_PASSWORD}</password>
</server>
</servers>
Also, update your pom.xml:
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
Make sure repository id and server id matches.
In this example, the id is "ossrh".
Also, note that the username and password should be same as your jira login. That's it mvn clean deploy will now upload your jar to sonatype repoditory. Happy Deploying!!
http://numberformat.wordpress.com/2011/05/18/nexus-repository/
I am following the above link to setup Maven and Nexus, everything new. I couldn't left a new comment there so I post here.
After so long, I am in another company, when I tried to setup a simple sample in my local PC, I got this error in "mvn deploy" to the simple Maven my-app sample. I installed the simple Nexus Open Source w/o Tomcat.
[WARNING] Could not transfer metadata com.mycompany.app:my-app:1.0-SNAPSHOT/maven-metadata.xml from/to snapshots (localhost:8081/nexus/content/repositories/snapshots): Access denied to: localhosts:8081/nexus/content/repositories/snapshots/com/mycompany/app/my-app/1.0-SNAPSHOT/maven-metadata.xml , ReasonPhrase:Forbidden.
In your settings.xml located in MAVEN_HOME/conf you have to add in servers section
<server>
<id>nexus-releases</id>
<username>deploy</username>
<password>123456</password>
</server>
And in your pom must looks like
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
Ids have to be the same.
Richard Seddon resolved my issue in nexus-users group.
Add this to nonProxyHosts:
localhost
You need to be authorized to run deployment. This is done by having the server section in your settings.xml. Check out the Nexus eval guide, specifically the publishing section and the sample projects in there for more detail.
We have a remote repository on a linux server. When I work on a linux machine I dont have any problem to access the repository with scp. I would like to work now on a windows machine on the project but I can't get the remote repository to work.
I followed these instructions: http://ekawas.blogspot.com/2007/02/maven-windows-and-deploying-to-remote.html
I have this in my settings.xml
<servers>
<server>
<id>ssh-repository</id>
<username>username</username>
<password>password</password>
<privateKey>C:\Dev\programs\ssh_private_key.ppk</privateKey>
<configuration>
<sshExecutable>plink</sshExecutable>
<scpExecutable>pscp</scpExecutable>
</configuration>
</server>
...
<profiles>
<profile>
<id>defaultProfile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>ssh-repository</id>
<name>SSH-Repository</name>
<url>scpexe://host:/path-to-rep</url>
</repository>
</repositories>
</profile>
</profiles>
When I just make pscp on the command prompt, I don't have any problems.
When I try mvn package or mvn clean, it gives the following error:
Non-resolvable parent POM: Could not transfer artifact .... from/ro ssh-repository ...
Is there something wrong with my settings.xml ?
The best recommendation i can give is to use a repository manager like Archiva, Artifactory or Nexus (alphabetical order). That will make you build running indepandant of the platform you are running. Furthermore it will make the configuration of the settings simpler.
Just if someone has the same problem. I managed to connect to my ssh repository from my windows machine with winscp.
here are the steps
install winscp
connect to your host with winscp
set settings of winscp -> memory -> save configuration in ini file
add ssh-rsa keys to know_hosts file > username.ssh\known_hosts
edit settings.xml in \username.m2\settings.xml
dont use sshExecutable and scpExecutable
use scp://hostname/location/to/repo
Anyway I can move the distributionManagement part outside the pom
I don't like the idea that my pom.xml contains server location,
Is it possible to move this or server name to settings.xml?
Thanks
<distributionManagement>
<repository>
<id>archiva</id>
<name>archiva Repo</name>
<url>http://ca.server:8080/archiva/repository/snapshots/</url>
</repository>
<snapshotRepository>
<uniqueVersion>false</uniqueVersion>
<id>archiva</id>
<name>archiva Repo</name>
<url>http://ca.server:8080/archiva/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
The best idea for this is to put such information into a parent POM (company pom) and use this instead of the settings.xml cause any body who wan't to build needs to change the settings.xml.
Short answer: Yes, you can.
Longer answer: I like the idea too, because I could imagine that the application will be built and distributed on different servers. So I like the following:
Define in the POM the dependencies to other libraries and plugins.
Define in your Maven installation configuration (so it is dependent on the installation, not on the user using that installation) what you have sketched out in your question.
Normally, you need a user-id and password to distribute in a Maven repository, and this is the (only) contents of it:
<settings>
<servers>
<server>
<id>archiva</id>
<username>XXadmin-user-nameXX</username>
<password>XXadmin-passwordXX</password>
</server>
</servers>
</settings>
This should only be on the build server configured by the build manager and not known by everyone. The only thing you have to ensure is that the IDs are the same in both files.