How to deploy an arbitrary binary to Nexus with maven - maven

I think I have run in to a maven deploy plugin bug, but I want to confirm that I am not doing it wrong before I open a bug report and start grepping through source.
I am trying to deploy an arbitrary binary (tar.gz,jar,box,etc) to a maven repository.
The user I am using is in the settings.xml file with a plaintext password.
The user is in an LDAP group that is connected to nexus with a Role.
That role has 3 privileges associated with it. Update, Create, Read which are in turn associated with the repository target.
Now using wget the user can pull data from the repo, and using this curl command I can deploy to the repo:
curl --request PUT --user USERNAME:PASSWORD https://NEXUS_URL/nexus/content/repositories/REPO_NAME/path/to/file/with/groupid/version/iamafile.jar \
--data #./iamafile.jar -H Content-Type:application/java-archive --verbose
This works fine, http 201 and the file is added. When I use a similiar mvn deploy command:
mvn deploy:deploy-file --settings /path/to/settings.xml \
-Durl=https://NEXUS_URL/nexus/content/repositories/REPOSITORYID -Dfile=iamafile.jar \
-DrepositoryId=REPOSITORYID -DartifactId=ARTIFACTID -DgroupId=GROUPID \
-Dversion=VERSION
I get an http 401 unauthorized error.
There have been multiple bug reports about this, but they supposedly have been fixed.
With a pom file with the same values for version, artifcatId, etc. mvn deploy works fine.
Have I found a bug, or am I using it improperly?
Edit:
I opened up this bug regarding the issue.
If the dev's end up saying that it isn't a bug, I will add that as an answer if someone hasn't beat me to it.

you need to additionally specify the -DrepositoryId

Related

How to download a JAR file using Maven command line with authentication?

I'm trying to use Maven command line (mvn) to download a JAR file.
This post helped me to get to this nice command:
mvn dependency:get -Dartifact=<group>:<artifact-name>:<version> -DremoteRepositories=...
But I still could not figure out how to pass an auth token (since it is a private repository).
I also tryied to append -DhttpHeader="Authorization: Bearer ..." with no success, but I don't remember where did I get this.
How can I set an authorization token for it, please?

Copy the latest artifact in the artifactory CURL

i have repo of snapshots like this:
www.arifactoryrepo.com/maven-last-dev/com/api/2.3.5-SNAPSHOT
In the snapshot directory i have a lot of of zip files:
morad-2.3.5-20201207_291847218.zip
morad-2.3.5-20201107_291847218.zip
morad-2.3.5-20201007_291847218.zip
when i click on the link of:
www.arifactoryrepo.com/maven-last-dev/com/api/2.3.5-SNAPSHOT/morad-2.3.5-SNAPSHOT.zip
it downloads for me the latest snapshot (morad-2.3.5-20201207_291847218.zip)
I need to copy the latest one to another path, so i used this command:
curl -u <USER:PASS> -X post "www.arifactoryrepo.com/artifactory/api/copy/maven-last-dev/com/api/2.3.5-SNAPSHOT.zip?to=/another/path.
and i get error of "failed to copy" maybe because the link is redirected.
so, there is anyway to copy the latest artifact ?
Thanks,
Morad.
The copy REST API does not support the translation of Maven unique snapshots.
You can use the artifact latest version API in order to get the correct version and then use it for the copy API, for example:
VERSION=$(curl -uuser:pass "https://myrepo.jfrog.io/artifactory/api/search/latestVersion?g=com.api&a=morad&v=2.3.5-SNAPSHOT&repos=libs-snapshot-local")
curl -uuser:pass -XPOST "https://myrepo.jfrog.io/artifactory/api/copy/libs-snapshot-local/com/api/moard/2.3.5-SNAPSHOT/morad-$VERSION.zip?to=/libs-snapshot-local/copy/me"

Something like “mvn undeploy” to remove artifacts from Nexus?

After a mvn deploy (to a local Nexus) on a project with more than 50 modules I realized that the deployed artifacts had all wrong file names (suffix zip instead of war etc).
Is there something like mvn undeploy to remove these from Nexus again?
You can delete it by using Curl command :
http://host:port/nexus/service/local/repositories/repo-id/content/group-id/artifact-id/version
The delete request can be sent with these parameters, I like to suppress the output except HTTP status code, so that it’s easier to check the result of a series of such commands run from shell script.
curl –request DELETE –write “%{http_code} %{url_effective}\\n” –user admin:admin123 –output /dev/null –silent url
For example you can execute this script from a Freestyle jenkins job.

Build Error while building aperturejs

I am trying to build aperturejs with Readme.md instructions.
I cloned the repository and tried the command mvn clean install in the root directory of ApertureJs.
I got the following Build Error as in the screenshot,
I am using the latest version of Maven - 3.3.9
Thanks in advance.
By reading the error in your console, I could feel that you are not authorized to access the particular repository, which is shown in your console.
Copy the repository url and try it from a browser - hope you will not be able to access the repository, since you are not authorized.
Raise appropriate access and after getting access, then try mvn clean install.
Below is the Quick fix till the time you get the access:
Copy and Paste the respective jar/pom/folder from your colleague machine, in your .m2/repository/...
Run the mvn clean install with -o option so that it will look into your local repository for building your application
Thank you. The issue is solved. I posted this issue to Uncharted Software's Salt Repository and exactly like Clement Said, I was trying to access a repository that no more has access publicly. Therefore they gave a workaround.
It is available here -> https://github.com/unchartedsoftware/aperturejs/issues/22
Thanks a lot.

Unable to download snapshot artifacts using curl from bintray.com

I'm automating the deploy process of a project and one of the things that I'm struggling is to download from Bintray the latest snapshot version of a given maven artifact.
This https://bintray.com/docs/api/#_dynamic_download documentation states that you should use $latest variable but all tentatives gave me a 404 error. Following is a curl sample
curl -v -H 'X-Bintray-Package: main' -utmoreira2020:mytoken 'https://bintray.com/content/liferay/myrepo/com/liferay/myproject/distribution/$latest/distribution-$latest.lpkg'
Thanks in advance
Couple of things that can go wrong here:
The dynamic content is only available for a Pro package (i.e. in a repo that belongs to a Pro user or a Pro organization).
Curl treats $ as a special character, you need to escape it with \. Here's an example: curl -u jbaruch -L "https://api.bintray.com/content/jfrog-int/iot-generic-distribution/firmare-\$latest.bin?bt_package=arduino-jfrog-firmware"
You are trying to download a Maven unique snapshot. This won't work because the version in the path is referred to as SNAPSHOT, while the version in the file name is the timestamp of the build. You might want something like Aritfactory's [SNAPSHOT] token, but that won't happen, because Bintray is a service for distributing releases, not development time snapshots (use Artifactory).

Resources