How to deploy to archiva using Jenkins and maven - maven

I am trying to deploy to my archiva repo using Jenkins and maven. I am using the "post-build actions" option: "deploy artifacts to maven repository" and I have added the configuration plugin where I added a settings.xml and defined the server details (id, username, password). I also added this file to "build environment" settings where I provided the file as a configuration file.
The problem I am having is the error: not authorized , reasonphrase: unauthorized.
The username and password are for a user with role "repository manager" as the archiva doc instructs. I have set up the pom.xml as well, like the documentation instructs.
I notice that the first error is:
ERROR: failed to retrieve remote metadata someGroupId:someArtifactId:someVersion-SNAPSHOT/maven-metadata.xml
I don't understand where the error comes from and how to resolve it. Please help.

Some suggestions:
1.) Ensure that you have all your servers listed in your Maven settings.xml. This gets me sometimes.
2.) Ensure that your snapshot repo id matches the repo id defined within Archiva.
3.) Ensure that you have access to the snapshots repo, even as admin. Permissions can be revoked.
4.) Ensure that you have the right password.
5.) I've had a restart of Archiva fix this problem before.
6.) The following settings.xml config will allow you to deploy snapshots to a custom snapshots repo that's part of a repository group (i.e. - a snapshots repo for a particular team):
<mirror>
<id><repo_group_id></id>
<mirrorOf>*, !<team_snapshot_repo_id></mirrorOf>
<name>My Team's Maven Repository</name>
<url>http://<HOST>:<PORT>/archiva/repository/<repo_group_id>/</url>
</mirror>
7.) Here's what I add to my pom.xml if I want to deploy the artifact to my snapshots Maven repo:
<distributionManagement>
<repository>
<id>internal</id>
<url>http://HOST:PORT/archiva/repository/internal/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>http://HOST:PORT/archiva/repository/snapshots/</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>snapshots</id>
<url>http://HOST:PORT/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

Related

How to change maven's Remote Repository URL in the NetBeans IDE (from http to https)?

When trying to run a NetBeans project, I get the following error message:
Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:2.10:test
(default-test) on project MyNetBeansProject: Execution default-test of goal
org.apache.maven.plugins:maven-surefire-plugin:2.10:test failed:
Plugin org.apache.maven.plugins:maven-surefire-plugin:2.10 or one of
its dependencies could not be resolved: Failed to collect dependencies
for org.apache.maven.plugins:maven-surefire-plugin:jar:2.10 (): Failed
to read artifact descriptor for
org.apache.maven.surefire:surefire-booter:jar:2.10: Could not transfer
artifact org.apache.maven.surefire:surefire-booter:pom:2.10 from/to
central (http://repo.maven.apache.org/maven2): Failed to transfer
file:
http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-booter/2.10/surefire-booter-2.10.pom.
Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]
The following part of the error message is the most important one:
Failed to transfer file:
http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-booter/2.10/surefire-booter-2.10.pom.
Return code is: 501 , ReasonPhrase:HTTPS Required.
Services -> Maven Repositories -> Central Repository -> right mouse click on "Central Repository" gives the following information:
As one can see, the Remote Repository URL is "http://repo.maven.apache.org/maven2/". I think it should instead be "https://repo.maven.apache.org/maven2/".
However, the problem is that I can't seem to change the Remote Repository URL.
Does anybody know how to change maven's Remote Repository URL in the NetBeans IDE?
UPDATE:
Under NetBeans -> Preferences one can see that the maven version used by my NetBeans IDE is Version 3.0.5:
Within the Netbeans installation, this worked for me:
Goto Netbeans installation folder > java > maven > conf, and here I updated the settings.xml file using administrative privilege.
as http repo link will not work now, just I created an mirror for central repo that is pre-built with IDE which cannot be changed.
Add this inside mirrors tag of settings.xml
<mirror>
<id>mirror1</id>
<mirrorOf>central</mirrorOf>
<name>mirror1</name>
<url>https://repo.maven.apache.org/maven2/</url>
</mirror>
after this restart netbeans IDE, and central repository will be overridden with the mirror we specify.
I think you have three options.
1. Migrate to 11.0
You can migrate to Netbeans 11.0 LTS (or 11.2), it uses a built-in Maven 3.3.9 version. It already uses https.
2. Install standalone Apache Maven
You can stay with Netbeans 8.2 but download standalone apache maven, install it to your system and set the path to the new maven home directory in Options -> Java -> Maven -> Maven Home.
You need just:
Download apache-maven-3.6.3-bin.zip (or apache-maven-3.6.3-bin.tar.gz) from Apache
Unzip it to any directory. It will be the Maven home.
Set the Maven home directory in NetBeans to the directory where you have extracted zip file.
Ensure than you have set JAVA_HOME in your environment variables
Instructions how to install standalone version here.
If you set the Maven Home in NetBeans correctly it will show you updated version:
3. Quick and not recommended
Just add repositories into your pom.xml with https (for example like that)
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
Maven Central Migrated to https
The problem comes from this:
As of January 15, 2020, The Central Repository no longer supports
insecure communication over HTTP and requires that all requests to the
repository are encrypted over HTTPS.
Here is the relevant improvement that was resolved and relevant changes.
Go maven>conf and update settings.xml
<profile>
<id>maven-https</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

Make local repository fall to the default repositories

I have a local nexus repository in my organization. I would like to make sure that when a new artifact needs to be loaded on a developer's machine it will first go to the local repository and if the artifact is not found fallback to the default maven repositories and download it to the local repository and then to the developer's machine.
Is using mirrorOf in each machine's settings.xml the way to go?
Defining a mirror in the settings.xml configures maven to override the location of a repository it is configured. Instead of using the location the repository requests it will use the one declared in the mirror.
To override the location of all repositories including the central repository add the following to the settings.xml file.
<mirrors>
<mirror>
<id>nexus-mirror</id>
<url>http://nexus.example.com:8081/nexus/content/groups/examplegroup/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
A nexus server can host group and proxy type repositories. A group repository allows you reference multiple over repositories. A proxy repository delegates to a remote repository and caches its artifacts.
In this case the examplegroup needs to be configured to include proxy respositories of the remote repositories you want to fallback to.
You can configure additional repositories in the pom.xml file. These are tried in addition to the default repositories.
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

Maven Project + Apache Maven + Apache archiva

This is what I did
As a first step, I have configured the Apache Archiva and the service runs perfectly as a standalone service though it created some trouble for me while trying to run in tomcat.
Edited the setting.xml in the MAVEN_HOME pointing to the Apache Archiva repository by adding mirror.
With the project's pom.xml, I see the following
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
Should I remove this to make my Archiva repository effective? I am afraid that this code makes a direct call from the Central repository without making use of the Archiva. Is this correct? Please advise
yes you can. This repository is the default one (and no need to declare it in your pom).
Just a mirror with <mirrorOf>central</mirrorOf> in your settings

Why is Maven downloading from the wrong repository?

I'm a newbie to Maven. I'm trying to setup a local Archiva 1.3.6 server to act as a repository server for a project's internal artifact, as well as mirror to external repos. Things work fine except for snapshots. I'm using Maven version 3.0.5.
Here are the mirror settings in my settings.xml file
<mirrors>
<mirror>
<id>internal</id>
<mirrorOf>external:*</mirrorOf>
<name>My Maven Repository</name>
<url>http://my.repo.server:9000/archiva/repository/internal/</url>
</mirror>
</mirrors>
During the build, Maven tries to download the snapshot artifact from the wrong repository. I have 2 repositories set in the parent's parent pom.xml: internal and snapshots.
<repositories>
<repository>
<id>internal</id>
<url>http://my.repo.server:9000/archiva/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://my.repo.server:9000/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
In the project's pom.xml I have the following dependency:
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>metadata-framework</artifactId>
<version>1.0.3.SNAPSHOT</version>
</dependency>
During the build Maven tries to do this:
Downloading:
.../archiva/repository/**snapshots**/com/mygroup/metadata-framework/1.0.3.SNAPSHOT/maven-metadata.xml
Downloaded:
.../archiva/repository/**snapshots**/com/mygroup/metadata-framework/1.0.3.SNAPSHOT/maven-metadata.xml (795 B at 16.9 KB/sec)
Downloading:
.../archiva/repository/**internal**/com/mygroup/metadata-framework/1.0.3.20130908.081541-1/cems-metadata-framework-1.0.3.20130908.081541-1.pom
[WARNING] The POM for com.myground:metadata-framework:jar:1.0.3.20130908.081541-1 is missing, no dependen
cy information available
I verified the files in snapshot repo is correct, that it has properly generated maven-metadata.xml and etc. it appears that Maven downloaded the metadata correctly from snapshot repo, determined the right timestamped version, but somehow it decided to download the actual file from internal repo instead of snapshots, which lead to 404 and failed build.
I have no idea how Maven works, please help.
#lee - Here's how I download custom artifacts from an internal snapshots repo within Archiva. I use this config every day.
settingsl.xml:
Let's say I have a virtual repo named "help".
help is comprised of outside-facing repos and 2 internal-facing repos. Those 2 internal-facing repos are:
help-internal
help-snapshots
Under the <mirrors> section, I declare:
<mirror>
<id>help</id>
<mirrorOf>*, !help-snapshots</mirrorOf>
<name>The Help Repository</name>
<url>http://blah:8080/archiva/repository/help/</url>
</mirror>
Under the <servers> section, I declare:
<server>
<id>help</id>
<username>my_user_name</username>
<password>{my_encrypted_pwd}</password>
</server>
<server>
<id>help-snapshots</id>
<username>my_user_name</username>
<password>{my_encrypted_pwd}</password>
</server>
And now the final bit. In my projects' pom's that use in-house snapshots, I include this:
<repositories>
<repository>
<id>help-snapshots</id>
<url>http://blah:8080/archiva/repository/help-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
More concisely, and without modifying any pom.xml, you could define an all repository group in archiva which contains both internal and snapshots, and then add the following in your .m2/settings.xml:
<mirrors>
<mirror><id>myGroup</id><mirrorOf>*</mirrorOf>
<url>http://my.repo.server:9000/archiva/repository/all/</url>
</mirror>
</mirrors>
<profiles>
<profile><id>alwaysactive</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository><id>unused</id><url>unused</url></repository>
</repositories>
</profile>
<profiles>
I know this post is old by in order for maven to search in a snapshot repository the version should end with "-SNAPSHOT" (rather than ".SNAPSHOT")

how to deploy my artifact on to my nexus?

I am using nexus open source as my repository manager for Maven 3.0.3
Maven is able to create artifact *.jar.
Now, I would like to know how I can push the generated artifact *.jar to the nexus repo manager, so that other dependent modules can pull from it.
I referred to this guide.
In settings.xml, I have
<server>
<id>nexus-site</id>
<username>admin</username>
<password>xxxx</password>
</server>
It fails.
How can invoke my deployment from mvn command or how to deploy my artifact on to my nexus?
Just try
mvn deploy
that will deploy your artifact to the nexus repo manager.
Have you configured the distributionManagement section ?
And if you want to add it to the snapshot repository, you need the following configuration inside your pom.xml
<distributionManagement>
<repository>
<id>nexus-site</id>
<name>MyCo Internal Repository</name>
<url>http://Nexus url</url>
</repository>
<snapshotRepository>
<id>nexus-site</id>
<name>Your Snapshot Repository</name>
<url>http://Nexus url</url>
</snapshotRepository>
</distributionManagement>
Repository element should also be specified.
Snippet:pom.xml
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>MyCo Internal Repository</name>
<url>http://Nexus url</url>
</repository>
</distributionManagement>
There are two ways to do so.
The first is do it via Nexus web interface, just upload the artifact with necessary project information (groupId, artifactId, version)
The other is using mvn deploy. You need to set distributionManagement for repository to upload to, and user to authenticate as.
The second approach is strongly recommended if you are going it do deployment regularly. It is automated, and you can leverage on other Maven commands like mvn release

Resources