I want to upload a JAR to a GitLab package registry - maven

I have a prebuilt JAR file that I want to upload into a GitLab package registry so it can be using when a build is performed.
This is my first time playing with Maven and uploading so newbie alert here!
In my project in GitLab I do see that there is a section titled "package registry". I assume that I need to upload it there.
I found the following command which I thought might do the trick:
mvn deploy:deploy-file -DgroupId=com.acme.group -DartifactId=project-name \
-Dversion=1.2.3 -Dpackaging=jar -Dfile="test.jar" \
-Durl=https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages
-DrepositoryId=project-name
I have no idea what to put in for "DrepositoryId", "DartifactId". The other field I assumed in what i put.
How do I know what to put in those fields?
I run it and get the following :
Uploading to remote-repository: https://gitlab-np.services.com/Ernie/ernie-sandbox-1/-/packages/com/acme/group/project-name/1.2.3/project-name-1.2.3.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.793 s
[INFO] Finished at: 2021-06-01T15:51:09-05:00
[INFO] ------------------------------------------------------------------------
[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 com.acme.group:project-name:jar:1.2.3 from/to remote-repository (https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages): transfer failed for https://gitlab-np.services.com/Ernie/ernie-sandbox-1/-/packages/com/acme/group/project-name/1.2.3/project-name-1.2.3.jar, status: 422 Unprocessable Entity -> [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
vanduyne-16mb:ernie-sandbox-1 vanduyer$ -DrepositoryId=project-name
bash: -DrepositoryId=project-name: command not found
Perhaps I need to allow permissions to upload to that location in GitLab - which I have no clue how to do.
Is that even where I should upload it to?
I have tried looking at the Maven sites and other sites for help on how to do this but I can not find something explaining this for a newbie.
Thanks for any help!

There are a few problems that I will list below.
First of all, you are missing a \ at the end of the third line. So, the -DrepositoryId=project-name parameter is not passing to the mvn deploy command.
Next, you need to decide which level do you want to deploy the artifact? You can read more about the levels on Gitlab's official documentation (GitLab endpoint for Maven packages). These addresses lead to /packages/maven, but you are missing the /maven token in the URL. (https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages)
You don't need to pass a repositoryId if you didn't configure any server inside your settings.xml file. If you configured it, then you can use the defined Id. So, Maven can use the configuration from the settings.xml file. You can read more about the repositoryId on Maven's official documentation: repositoryId
The groupId and artifactId parameters are the required parameters that define how you can import the artifact from the repository. I suggest you use the same groupId and the artifactId configured inside the pom.xml file of the artifact. If you deploy a package with groupId=com.group and artifactId=artifact-id then you can import the artifact to your project like this:
<dependencies>
<dependency>
<groupId>com.group</groupId>
<artifactId>artifact-id</artifactId>
<version>...</version>
</dependency>
...
</dependencies>
I suggest read more about deploying to Gitlab's Maven repository since you have to configure the authentication section as well: Maven packages in the Package Repository

Related

Why deploying maven packages on terminal throws an error but the maven package ends up being published on GitHub packages anyway?

I have been using Clojure, ClojureScript, lein, shadow-cljs, re-frame,
reagent, Emacs, and CIDER to work on a Clojure/ClojureScript dynamic
web app project.
Now, I am trying to make depencies be private Maven packages hosted
for free on GitHub packages. Ok, I managed to publish a package!
After the successful attempt to publish my first maven package, it
ended up with the name of repository-name.repository-name
which looks ugly. As I was trying to tweak it, I ended up changing
this line on my project.clj file:
:pom-addition [:distribution-management [:repository [:id "github"]
[:name "GitHub Packages"]
[:url "https://maven.pkg.github.com/organization-name/repository-name"]]])
Instead of [:url "https://maven.pkg.github.com/organization-name/repository-name"] I
tweaked it to be [:url "https://maven.pkg.github.com/organization-name"].
Now, things got really weird in my opinion.
After executing the terminal command to publish it:
➜ mvn deploy -DaltReleaseDeploymentRepository="${REPO}" -DaltSnapshotDeploymentRepository="${REPO}"
The terminal throws:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.563 s
[INFO] Finished at: 2022-10-28T12:33:16-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project project-name: Failed to retrieve remote metadata project-name:project-name/maven-metadata.xml: Could not transfer metadata project-name:project-name/maven-metadata.xml from/to github (https://maven.pkg.github.com/organization-name): transfer failed for https://maven.pkg.github.com/organization-name/project-name/project-name/maven-metadata.xml, status: 422 Unprocessable Entity -> [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
Now, when I go to https://github.com/orgs/my-organization/packages, the package was indeed published!
And with the name of repository-name instead of repository-name.repository-name.
Why is that so? If the build failed, why is the packaged being published?
Also, what would be standard name for Maven packages on GitHub
packages (especially considering these are Maven packages for a
Clojure project)?

can not create project for opendaylight With Maven Archetype

I want create project for opendaylight with Maven Archetype and import into eclipse but when type this code for create project
mvn archetype:generate -DarchetypeGroupId=org.OpenDaylight.controller -DarchetypeArtifactId=OpenDaylight-startup-archetype -DarchetypeRepository=https://nexus.OpenDaylight.org/content/repositories/public/ -DarchetypeCatalog=https://nexus.OpenDaylight.org/content/repositories/public/archetype-catalog.xml
this will make the error
Generating project in Interactive mode
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.004 s
[INFO] Finished at: 2018-04-30T19:47:52+04:30
[INFO] Final Memory: 14M/138M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-
plugin:3.0.1:generate (default-cli) on project standalone-pom: archetypeCatalog 'https://
nexus.OpenDaylight.org/content/repositories/public/archetype-catalog.xml' is not
supported anymore. Please read the plugin documentation for details. -> [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/
MojoFailureException
how to can resolved this problem ?or create new project?
EDIT: This option is displayed when you check create simple project
I always prefer to start building the ODL application through Eclipse.
Select "Create Maven Project" and click next which will ask you to fill various details. Fill the details as follows:
Artifacts:
Group ID: org.opendaylight.yourprojectname
Artifact ID: yourprojectname
Version: 1.0.0-SNAPSHOT
packaging: pom
Parent
Group ID: org.opendaylight.odlparent
Artifact ID: bundle-parent
Version: 1.8.1-Carbon (or any other stable version)
wait for eclipse to download all related components.
PS: I am assuming you have your settings.xml file updated. If Not use this settings.xml to update your existing settings.xml accordingly
And now you are good to go.
The official documentation for how to use Maven archetype is here: http://docs.opendaylight.org/en/latest/developer-guide/developing-apps-on-the-opendaylight-controller.html
It was more or less broken in previous releases, and has recently been fixed on the master branch for the future Fluorine release; more details here: https://jira.opendaylight.org/browse/DOCS-60 and

Spring MVC issues in STS 3.7.3

I am getting this error on importing https://github.com/spring-projects/spring-mvc-showcase in STS 3.7.3:---
Description Resource Path Location Type
Failure to transfer org.codehaus.mojo:aspectj-maven-plugin:pom:1.2 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.codehaus.mojo:aspectj-maven-plugin:pom:1.2 from/to central: connect timed out pom.xml /spring-mvc-showcase line 1 Maven pom Loading Problem
Edit
Mvn is ok now but pom.xml error still persists if I remove the errors and do maven clean I get errors as:
[INFO] https://repo.maven.apache.org/maven2/org/codehaus/mojo/aspectj-maven-plugin/1.2/aspectj-maven-plugin-1.2.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [ERROR] Plugin org.codehaus.mojo:aspectj-maven-plugin:1.2 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.mojo:aspectj-maven-plugin:jar:1.2: Could not transfer artifact org.codehaus.mojo:aspectj-maven-plugin:pom:1.2 from/to central: connect timed out -> [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/PluginResolutionException
First of all STS is build on Eclipse. So you can easily install the IDE Integration Eclipse IDE - M2Eclipse for STS. You can see how here. If you want to use it with this integration plugin you dont need to have a local maven repository.
Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository
But its also possible to use maven as a local system repository. Download is here and follow the steps for the installation and configuration here.
To see if you have a valid maven installation done, you can test it by typing mvn -v in a cmd shell or using STS -> right click on your project -> run as -> maven build or maven install.
Update:
I would say delete the project from your workspace and try it again. Download the project from gitHub as a zip file and import it again to your workspace. Right Click -> import -> existing maven project.
If you need to use a proxy for your connection you have to create a settings.xml in your .m2 folder. Look here for more info

maven deploy:deploy-file fails (409 Conflict), yet artifact uploads successfully

NOTE:
I now realize that the jar got placed into my repository, but the pom.xml did not. Now, I have another project where the pom.xml fails to get promoted, but the jar is placed in the repository.
However, another project, both the pom.xml and the jar do get placed in the repository.
I have a project in Jenkins where I use the promotion plugin to deploy my artifacts in Maven via the deploy:deploy-file goal.
This works for several other projects I have in Maven, but it fails for this project. The funny thing is that the file (but not the pom.xml) uploads anyway. I've verified this by removing the artifact from our Maven repository, then running the promotion. The artifact is in our repository after the promotion.
Here's the log I'm getting. Broke up the extra long lines the best I could:
[workspace] $ /bin/bash -xe /opt/tomcat/apache-tomcat-7.0.27/temp/hudson7357923598740079329.sh
+ FILE_LOC=/mnt/jenkins/builds/metricsdb-trunk/21/archive/target/archive
+ mvn deploy:deploy-file
-Dversion=0.8.0
-Dfile=/mnt/jenkins/builds/metricsdb-trunk/21/archive/target/archive/metricsdb-etl.jar
-DpomFile=/mnt/jenkins/builds/metricsdb-trunk/21/archive/target/archive/pom.xml
-Durl=http://repo.vegicorp.com/artifactory/ext-release-local -DrepositoryId=VegiCorp
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Command Line Spring Batch Module 0.8.0.CI-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) # metricsdb-etl ---
Uploading: http://repo.vegicorp.com/artifactory/ext-release-local/com/vegicorp/batch/metricsdb/metricsdb-etl/0.8.0/metricsdb-etl-0.8.0.jar
2/38 KB
4/38 KB
[...]
Uploaded: http://repo.vegicorp.com/artifactory/ext-release-local/com/vegicorp/batch/metricsdb/metricsdb-etl/0.8.0/metricsdb-etl-0.8.0.jar (38 KB at 202.2 KB/sec)
Uploading: http://repo.vegicorp.com/artifactory/ext-release-local/com/vegicorp/batch/metricsdb/metricsdb-etl/0.8.0/metricsdb-etl-0.8.0.pom
2/7 KB
4/7 KB
[...]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.243s
[INFO] Finished at: Thu Oct 04 14:38:52 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 metricsdb-etl: Failed to deploy artifacts:
Could not transfer artifact com.vegicorp.batch.metricsdb:metricsdb-etl:pom:0.8.0 from/to
VegiCorp (http://repo.vegicorp.com/artifactory/ext-release-local):
Failed to transfer file: http://repo.vegicorp.com/artifactory/ext-release-local/com/vegicorp/batch/metricsdb/metricsdb-etl/0.8.0/metricsdb-etl-0.8.0.pom.
Return code is: 409, ReasonPhrase:Conflict. -> [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
failed build hudson.tasks.Shell#24a6e7f9 SUCCESS
Finished: FAILURE
Output with the debug flag (-X) is in Pastebin.
I found the problem. Two problems actually:
I only had the release repository setup, and I was attempting to save a snapshot release in the release repository. Artifactory was setup to only allow releases in the release repository. This can be modified in the Artifactory setting, but I decided against this.
My pom.xml has a different version in it than I was trying to save it to. For example, the pom.xml said version 2.0 and I was trying to save the release as 2.0.2. Artifactory rejected the pom (but not the jar) for this reason.
I found the Artifactory setting (which is per repository) that asks whether or not to "Suppress POM consistency checks". Checking this box will allow me to set the version to one, but have the pom say another.
I also had to modify my Maven "settings.xml" file to allow for both a Release and Snapshot repository. I also have to modify my URL to the snapshot repository.
We were only using Ivy for a while (which doesn't have a snapshot concept), so we were just putting stuff in the release repository. This is a Maven project, and the developer marked the version in the POM as a SNAPSHOT.
Unfortunately, Maven documentation is pretty poor, and there still aren't any good books on Maven. Even worse is that the error messages are simply poor. What does "409, ReasonPhrase:Conflict. -> [Help 1]" mean?
Not that Ivy documentation is so much better, but Ant in Action has some excellent sections on using Ivy.
Ensure that you include -SNAPSHOT as part of your version if you are publishing to the snapshot repository.
And remove -SNAPSHOT in case you are publishing it to a non-snapshot repository.
Yeah....Multiple Reason for same error. May be it will help somebody
1. Login as Admin to Artifactory
2. Configuration -> Repositories
3. Edit the Local Repository ---> Suppress POM Consistency Checks
This solves my problem.... Not sure. Right approach or not ?
I also face this problem, and I found the reason is the parent project didn't deploy in the snapshot repository.
I run mvn deploy in the parent folder, and the problem resolved.
Had that error message too. For me the problem was that the setup of the server is to accept only release, not SNAPSHOT. After removing the SNAPSHOT from the pom, it worked fine.
In my case the POM file associated with the jar file (external, in same dir) had a dependency to itself. This was a offline zipped repo from a third party that I needed to load into artifactory.
I modified the POM files, removed the self-dependency and made sure the package info was right. Then artifacts deployed with no problems. Sent email to vendor so they can fix in their build.
I had this issue as well and it turned out that we had include/exclude rules set up on the repository I was trying to deploy to and my deployment didn't match those rules.
My solution was to point the deployment at a new repository that had **/* as the include rule (and the pattern from my other repository as an exclude rule to keep them separate).
I have been experiencing the same problem.
(TL;DR: solution see last line)
During the deploy from jenkins to Artifactory, sometimes (magic!) a 409 - conflict error appeared with the following error message on the Artifactory log:
[WARN ] (o.a.e.UploadServiceImpl:239) - Sending HTTP error code 409: Checksum policy 'LocalRepoChecksumPolicy: CLIENT' rejected the artifact 'gradle-integration:com.redacted.java/fooProject/123/foo-123.jar'. Checksums info: ChecksumsInfo{checksums={SHA-1=ChecksumInfo{type=SHA-1, original='da39a3ee5e6b4b0d3255bfef95601890afd80709', actual='1459689f0be058f4ecef7e6fe3576f1550a8afda'}, MD5=ChecksumInfo{type=MD5, original='d41d8cd98f00b204e9800998ecf8427e', actual='14c7a498de028d6eb5882b3c698bc456'}}}.
As the trained eye might notice: The MD5# d41d8cd98f00b204e9800998ecf8427e is the checksum for an empty file or string.
Which means that the following must be happening:
The copy job that prepares the Artifacts in the publish folder had not finished and therefore the file was empty when the checksum was calculated.
However when the deploy happened the file was there, Artifactory now receives a checksum which is incorrect and correctly refuses the file with the error code 409.
THE SOLUTION (is simple):
Make 100% sure the files are definitely there before you start the deploy job (add a pause or proper logic).
There is a good possibility that the space on your remote repo is full. Verify that before going all technical and wasting time. Wasted 2-3 hrs thinking its a logical problem.
In my case the root cause for that very error was dependency version property that was not in the root pom.
The solution was moving the property to root pom where the version for the dependency was required.
So, missing version property of a dependency.
Very misleading error message indeed.
The world snapshot was written in lower case inside the pom.xml file. It must be written in upper case.
Ali

Maven missing project required libraries after cloning repo

A team member has shared his project with me on bitbucket and he used maven to manage his dependencies. After cloning the repo (using mercurial) into my workspace (Eclipse) and downloading maven, m2e and all the other required set up files i was able to get all of the project libraries except for 4.
After downloading the project, i ran several mvn commands to clean, install and hopefully download these missing jars. When i ran mvn -e command i get this long error that does nothing to help. Do i have to find and download these 4 jars and put them in my maven repo?
Command output: mvn -e
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.769s
[INFO] Finished at: Mon Apr 09 17:42:17 CDT 2012
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Dugsi_Manager: Could not resolve depen
dencies for project org.bixin.dugsi:Dugsi_Manager:war:0.1.0.BUILD-SNAPSHOT: The
following artifacts could not be resolved: org.eclipse.persistence:eclipselink:j
ar:2.2.0, org.eclipse.persistence:javax.persistence:jar:2.0.3, org.vaadin:icepus
h-gwt:jar:0.1.2, org.jqurantree:jquran:jar:1.0.0: Could not find artifact org.ec
lipse.persistence:eclipselink:jar:2.2.0 in spring-maven-release (http://maven.sp
ringframework.org/release) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
EDIT:
I just need to share my local repository with all other team members that clone my project. External jars that dont use maven have to be manually installed into my local repo, this creates a problem because i cant share my local repo? Any ideas
You can either install these JARs in your local repository, or setup an own (possibly private) maven repository for you to share with your team. Sonatype provides with Nexus OSS an open-source based software to easily set up a repository (which also proxies remote ones if you like).

Resources