Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy Github Packages - maven

I am trying to deploy my artifact as a packaged to Github Packages. On clean deploy I get
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project cardgame: Failed to deploy artifacts: Could not transfer artifact org.moderatelycomfortablechair:cardgame:jar:0.0.1-20201222.145834-1 from/to github (https://maven.pkg.github.com/ModeratelyComfortableChair/CardGame): Access denied to https://maven.pkg.github.com/ModeratelyComfortableChair/CardGame/org/moderatelycomfortablechair/cardgame/0.0.1-SNAPSHOT/cardgame-0.0.1-20201222.145834-1.jar. Error code 403, Forbidden -> [Help 1]
My pom.xml contains the following
<modelVersion>4.0.0</modelVersion>
<groupId>org.moderatelycomfortablechair</groupId>
<artifactId>cardgame</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cardgame</name>
...
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub ModeratelyComfortableChair Apache Maven Packages</name>
<url>https://maven.pkg.github.com/ModeratelyComfortableChair/CardGame</url>
</repository>
My ~/.m2/settings.xml is the same as here, where username and owner is ModeratelyComfortableChair (my github username) and password is a personal access token with repo and read write access.

Firstly you need to have read:write access to packages on your Personal Access Token (PAT). That should solve your problem.
This works very well with your private repositories.
However, for those working with organization repositories and having Single Sign-On (SSO) enforced, this might not be sufficient. The token must be explicitly authorized for SSO. And Maven command doesn't prompt for that.
There are different ways to authrorize the token, two of which are as explained below.
[Easiest] Login to GitHub account and navigate to the PAT section. There you'll find an option to enable SSO for the given token. (Token name could be different in your case)
Try to clone your repository using Git commandline - git clone https://[USERNAME]:[TOKEN]#[GIT_ENTERPRISE_DOMAIN]/[ORGANIZATION]/[REPO].git
It will throw an error and give you a URL for authorizing the token with SSO. Access the URL in a browser and authorize the SSO for the given token. Once authorized, you should be able to publish/deploy your artifacts.
Cheers!

Related

azure-storage-wagon: Server failed to authenticate... Make sure ... Authorization header is formed correctly including the signature

When trying to follow the instructions at this link, I am getting an authentication failure from azure-storage-wagon lib.
Here is how I configured my pom.xml :
<distributionManagement>
<snapshotRepository>
<id>my-repo-bucket-snapshot</id>
<url>http://stacctname99.blob.core.windows.net/snapshot</url>
</snapshotRepository>
<repository>
<id>my-repo-bucket-release</id>
<url>http://stacctname99.blob.core.windows.net/release</url>
</repository>
</distributionManagement>
And, in my .m2/settings.xml, I configured it like so:
<servers>
<server>
<id>my-repo-bucket-snapshot</id>
<username>stacctname99</username>
<password>XXrO5jvcWjtTcW/........MPrLIJsvb7A0Na3VK/Tg==</password>
</server>
<server>
<id>my-repo-bucket-release</id>
<username>stacctname99</username>
<password>XXrO5jvcWjtTcW/.......MPrLIJsvb7A0Na3VK/Tg==</password>
</server>
</servers>
And here is the error that I get on mvn deploy . It makes me wonder if I shouldn't use a https/http url?
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy
(default-deploy) on project storage-wagon-poc: Failed to deploy
artifacts: Could not transfer artifact
com.st.azure:storage-wagon-poc:jar:1.0-20220518.171854-1 from/to
my-repo-bucket-snapshot
(http://stacctname99.blob.core.windows.net/snapshot):
authorization failed for
http://stacctname99.blob.core.windows.net/snapshot/com/st/azure/storage-wagon-poc/1.0-SNAPSHOT/storage-wagon-poc-1.0-20220518.171854-1.jar,
status: 403 Server failed to authenticate the request. Make sure the
value of Authorization header is formed correctly including the
signature.
NOTE1: My storage account does not require https. My storage account is public access to both blobs and container. In debug mode, this azure-storage-wagon extension does not show me the header it sends in the request. How would you troubleshoot? Do you see a typo in my setup? The GitHub repo does not allow creating a new issue.
NOTE2: The lib seems to be looking for 6 env variables: https://github.com/Azure/azure-sdk-for-java/blob/83f62af66b349c4dc663489570ad78f97dfee2b1/sdk/identity/azure-identity/src/main/java/com/azure/identity/EnvironmentCredential.java BUT I am unsure where to find some of those values since the storageapp in azure portal does not just show them to you.

Configure Nexus connection for maven deployment

Im trying to gain some experience in working with Nexus and TeamCity.
To do so i set both servers up on my local machine and configured a pet project thats located on github.com in a private repo.
But i can't get my TC-Build to run because the Maven deploy step fails with following message.
[14:58:55][Step 2/2] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project Worm: Failed to deploy artifacts: Could not transfer artifact org.test.worm:Worm:jar:1.0.0 from/to local_nexus (http://localhost:8081/repository/org.test): Transfer failed for http://localhost:8081/repository/org.test/org/test/worm/Worm/1.0.0/Worm-1.0.0.jar 401 Unauthorized
Seems like it fails due to wrongly configured authorization but i can't find the mistake.
In my projects pom.xml it is configured like this
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test</url>
</repository>
</distributionManagement>
and in my mavens settings.xml like this
<server>
<id>local_nexus</id>
<username>admin</username>
<password>admin</password>
</server>
Im using the default admin user (user/pw is correct, logging into nexus with the same user) that is created when installing nexus. Same user that created the repository.
TC running under localhost:8080 and Nexus under localhost:8081
Please tell me what i configured wrongly or what i forgot.
Using mvn help:effective-settings i could confirm that the settings.xml was configured correctly. But it made me realize that my TeamCity Server was using a different (its own) maven instance than my local machine. So the solution was to either set the maven-home for TeamCity or to configure the settings.xml of the other maven instance.
Stupid mistake i should have noticed way sooner.

Maven settings.xml with an Artifactory <server/> using SSH keys for authentication

Using the Artifacory generated maven settings I can run mvn deploy, the build completes, and artifacts are deployed successfully.
With the ability to upload a public key to Artifactory (see: https://jfrog.com/article/ssh/), I was hoping to swap out the username/password in the generated ~/.m2/settings.xml with a privateKey/passphrase pair (see: https://maven.apache.org/settings.html#Servers).
Unfortunately, switching from username/password to privateKey/passphrase I get the following "Not authorized" error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project my-project: Failed to retrieve remote metadata com.test:my-project:1.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.test:my-project:1.0-SNAPSHOT/maven-metadata.xml from/to my-artifactory (https://na.artifactory.xxxx.com:443/artifactory/my-artifactory-local): Not authorized -> [Help 1]
Does Artifactory support privateKey/passphrase authentication from Maven? Or, is it possible to use something other than username/password (API Key maybe?) to allow Maven to authenticate?
I don't know about getting public key authentication to work with Artifactory and Maven, but at least with Artifactory 6.15.1 you can use the Artifactory API Key for your account instead of the password. In the Artifactory web UI, click on your login name to open your profile, enter your current password to unlock your profile, then copy the API Key and paste it in to the <servers> section of your Maven settings.xml, replacing ARTIFACTORY_USERNAME and ARTIFACTORY_API_KEY in the sample below:
<servers>
<server>
<id>central</id>
<username>ARTIFACTORY_USERNAME</username>
<password>ARTIFACTORY_API_KEY</password>
</server>
<server>
<id>snapshots</id>
<username>ARTIFACTORY_USERNAME</username>
<password>ARTIFACTORY_API_KEY</password>
</server>
</servers>

Could not transfer artifact - not authorized

I want to use an artifact "eu.excitementproject:lap:jar:1.1.0:" from the following repository:
http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject
I can download the jar directly from the above link without any authorization.
However, when I mvn install on my computer, I get the following error:
Could not transfer artifact eu.excitementproject:lap:pom:1.1.0 from/to excitement
(http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject):
Not authorized
Here is the relevant part of my pom.xml:
<repositories>
<repository>
<id>excitement</id>
<name>excitement</name>
<url>http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>eu.excitementproject</groupId>
<artifactId>lap</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
What should I do?
Your Maven configuration is:
repository URL - http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject
group-id - eu.excitementproject
artifact-id - lap
artifact-version - 1.1.1.
The full path to the artifact is therefore http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject/eu.excitementproject/lap/1.1.1/lap-1.1.1.pom.
If I hit this URL from any web browser, I am asked to authenticate using basic HTTP authentication. This is exactly what Maven also sees. Therefore, as #Will mentioned above, if you wish to continue using this repository URL, you will have to configure authentication settings for the repository in your local settings.xml.
Interestingly, I can hit http://hlt-services4.fbk.eu:8080/artifactory/repo/eu.excitementproject/lap/1.1.1/lap-1.1.1.pom without problems. So, if you shorten your repository URL to http://hlt-services4.fbk.eu:8080/artifactory/repo, your build will work (I have tested this).
you can provide credentials to your artifactory using basic url authentification(https://developer.mozilla.org/en-US/docs/Web/HTTP/Basic_access_authentication).
In your case repository url should be:
http://USERNAME:PASSWORD#hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject

Unable to deploy Maven artifacts to snapshot/private Cloudbees repository

I'm using an Ant script to deploy artifacts to my snapshot/private repository but I'm getting a Forbidden exception as follow. Looks like that the username and password are correct because if I change them I get a different error (unauthorized). What I'm missing?
[exec] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom:
Failed to deploy artifacts: Could not transfer artifact br.com.simpleconsulting.portal:portal-client:jar:6.1.0-20121007.102101-1 from/to cloudbees-snapshot (https://repository-tmoreira2020.forge.cloudbees.com/snapshot):
Access denied to: https://repository-tmoreira2020.forge.cloudbees.com/snapshot/br/com/simpleconsulting/portal/portal-client/6.1.0-SNAPSHOT/portal-client-6.1.0-20121007.102101-1.jar, ReasonPhrase:Forbidden. -> [Help 1]
2 common causes of an unauthorized error (403) on CloudBees infrastructure are
uploading with valid credentials that don't have authority to the path in question
uploading with valid credentials to a URL path that doesn't exist
I can see that the URL path listed exists and contains new artifacts - did you get things working after you posted this question?
Try passing settings.xml explicitly to your maven commands:
mvn -s ~/.m2/settings.xml deploy
Also, ensure that you have webdav-jackrabbit extension configured in the build section of your maven pom.xml
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.2</version>
</extension>
</extensions>

Resources