Maven Project + Apache Maven + Apache archiva - maven

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

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>

How to deploy to archiva using Jenkins and 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>

Take artifacts from multiple repositories with Maven

How can I configure a maven project to take one of the artifacts from a different repository?
I would like to include this in the project https://github.com/twitter/hadoop-lzo but I can find it only in the twitter repository, not on the central maven repository.
You can set the repositories you want to use in your settings.xml, or in your POM.
If you have a team working on the project, you might want to put this in the POM so everybody has the conf.
You can do it like :
<repositories>
<repository>
<id>Maven Central</id>
<url>http://repo1.maven.org/maven2/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
.... other repos
</repositories>

Maven repository lookup order

We have an internal Apache Archiva based repository and we have configured the repositories tag in pom.xml to be as follows. Can I assume that all dependency access will get resolved by internal repository if you have access to it and will get resolved by other repositories listed below, if internal repository is down for a certain reason.
<repositories>
<repository>
<id>internal</id>
<name>Internal Repository</name>
<url>http://192.168.1.2/archiva/repository/internal</url>
</repository>
<repository>
<id>jboss</id>
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
....
</repositories>
EDIT:
I want to do away with the .m2/settings.xml file. I want to define this in my pom.xml file, so that if my repository manager is UP and running I would want the runtime to connect there, else would want to fallback into the other repositories. Would this be possible?
Maven 3.0 had it fixed as you can see in Maven developer's Jira below. The lookup will be done in the order they are declared.
https://issues.apache.org/jira/browse/MNG-4400

Why is maven looking for artifact in the wrong repo?

I'm defining a dependency in pom.xml in a Maven 3 project. Dependency is as follows:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<scope>runtime</scope>
<version>2.2</version>
</dependency>
Repostory is described in pom as follows:
<repository>
<id>java.net</id>
<name>java.net</name>
<url>http://download.java.net/maven/2</url>
</repository>
Artifact is indeed present in the repository. It's easy to check. Despite that, Maven is trying to obtain the artifact from repo1.maven.org. What could be the reason of this? Maybe I make some crucial mistake in defining repository access? Other dependencies seem to do fine.
Plugin org.mortbay.jetty:maven-jetty-plugin:6.1.26 or one of its
dependencies could not be resolved: Could not find artifact
org.glassfish.web:el-impl:jar:2.2
in central (http://repo1.maven.org/maven2)
The repository that you have defined is used for dependencies, but not for plugins. Hence the error.
To address this, you need to define pluginRepositories:
<project>
<!-- ... -->
<pluginRepositories>
<pluginRepository>
<id>{repo.id}</id>
<url>{repo.url}</url>
</pluginRepository>
</pluginRepositories>
</project>
As to where you should specify - in pom.xml or settings.xml, read this SO post.
You need to check your maven settings.xml (Look into Maven folder: M2_HOME/conf).
The default repositories are defined there itself, and Maven central repository is taking precedence.
Define your repository in Maven's settings.xml like this:
<profiles>
<profile>
...
<repositories>
<repository>
<id>Java Net</id>
<name>Java Net</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
...
</pluginRepositories>
...
</profile>
You can maybe overwrite the default Maven central repository location with yours if you don't want to do much configuration.
Cheers!
In my case, the real root issue was that the repo required authentication. However for some reason maven decided that it would be much better to not tell me that, and to instead use the first repo in the <repositories> list, and throw the Could not find artifact error for that repo.
After moving the repo that contained the package so it was the first one in the <repositories> list, it started showing me a "permission denied" message. Once maven was setup for authentication with the repo in question, the issue went away.
I had a similar problem however, another developer had set up a mirror in that I simply copy-pasted into my settings.xml file. Modifying the mirrorOf property to only include specific repos did the trick.
In addition to the above mentioned answers, make sure your settings.xml is saved as an xml file not a text file i.e. its not saved settings.xml.txt.

Resources