how is Maven 3 host look up different to Maven 2? - maven

I am working to migrate from Maven 2 to Maven 3. I have purposely removed the host and port from the messages and settings.
Maven 2 currently works fine with the Artifactory central repository we have setup behind a firewall. When I switch to using Maven 3 it fails to download the plugins with the error message:
[ERROR] Plugin org.apache.maven.plugins:maven-install-plugin:2.3.1 or
one of its dependencies could not be resolved: Failed to read
artifact descriptor for org.
apache.maven.plugins:maven-install-plugin:jar:2.3.1: Could not
transfer artifact
org.apache.maven.plugins:maven-install-plugin:pom:2.3.1 from/to
central (http:/ /:/artifactory/plugins-release): Access
denied to:
http://:/artifactory/plugins-release/org/apache/maven/plugins/maven-install-plugin/2.3.1/maven-install-plugin-2.3.1.pom
, ReasonPhrase:Forbidden.
Here are my settings:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<proxies>
<proxy>
<id>andy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxyip</host>
<port>80</port>
<username>user</username>
<password>password</password>
<nonProxyHosts>host</nonProxyHosts>
</proxy>
</proxies>
<servers>
<server>
<username>user</username>
<password>password</password>
<id>central</id>
</server>
<server>
<username>user</username>
<password>password</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://<host>:<port>/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://<host>:<port>/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://<host>:<port>/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://<host>:<port>/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
I have checked that the correct plugin and version exists in artifactory, this does seem to be an access issue. Has something changed between Maven 2 and Maven 3 where the configuration needs updating?

There is a typo in the configuration (probably settings.xml or a POM file): http://:/artifactory/ isn't a valid URL, try http://artifactory/ instead.
EDIT If the URL is valid in a browser, then Maven has no access.
What the error message says: Maven tried to download the file and the server responded with HTTP status 403 (Forbidden). Since it works with a web browser, this is most certainly a problem with settings.xml and permissions on the Artifactory server.
I once had a similar problem with Nexus; it was configured to deny access to certain packages.
Check the log files of the repository server. You can also try to remove any <server> entries in settings.xml - the browser also connects without logging in. And (of course) make sure user names and passwords are correct.

You defined a proxy between your machine and your Artifactory server on the intranet. Usually, that is not the correct setup. Artifactory might need a proxy to reach the servers on the internet (the remote repositories), but maven probably must access Artifactory without proxy.

I fixed this issue by re-downloading and refreshing my Maven 3 install. There must have been something wrong with the install.

Related

Maven Bnd Repository Plugin fails to fetch artifact from remote artifactory

I'm trying to get bnd tools structure working (started with tutorial https://bndtools.org/tutorial.html)
Added use of javax.vecmath (as simple library as I could think of) in cnf/central.maven file
javax.vecmath:vecmath:1.5.2
and added it to build path in org.example.impl with everything resolving just fine.
I have fork of this library in jFrog artifactory running on remote server, so next step was defining that repository in cnf/build.bnd adding (as described in https://bnd.bndtools.org/plugins/maven.html)
-plugin.10.Remote = \
aQute.bnd.repository.maven.provider.MavenBndRepository; \
releaseUrl=https://artifactory.website.com/artifactory/libs-release-local/; \
snapshotUrl=https://artifactory.website.com/artifactory/libs-snapshot-local/; \
index=${.}/release.maven; \
name="Maven Remote"
and appropriate reference in cnf/release.maven
javax.vecmath:vecmath:2.1.5
When adding this library to build path I get error "2.1.5 [Could not fetch javax.vecmath:vecmath:2.1.5]" with no further information.
I figured the only difference between maven central and my artifactory should be content of .m2/settings.xml with credentials (according to https://bnd.bndtools.org/instructions/connection-settings plugin should look there in the first place).
Configuration that works for maven in eclipse (when I open a maven project that has vecmath 2.1.5 as dependency it gets pulled without a problem to .m2/repository/javax/vecmath/vecmath/2.1.5 and once there it gets resolved just fine by bnd)
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>username</username>
<password>roigonsdnglosgnoisfgnsdjgnlafjksasgnl</password>
<id>central</id>
</server>
<server>
<username>username</username>
<password>roigonsdnglosgnoisfgnsdjgnlafjksasgnl</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>https://artifactory.website.com/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>https://artifactory.website.com/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>https://artifactory.website.com/artifactory/libs-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>https://artifactory.website.com/artifactory/libs-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
From this it seems bnd has no problem fetching from maven central to local m2 repository and using it from there, but fails to connect to my artifactory. Is there some key setting or difference I'm missing?
Ended up solving the issue with help from https://groups.google.com/forum/#!forum/bndtools-users having found two (three?) problems with my configuration.
The correct form for repository definition in build.bnd seems to be
-plugin.10.Remote: \
aQute.bnd.repository.maven.provider.MavenBndRepository; \
releaseUrl=https://artifactory.website.com/artifactory/libs-release-local/; \
snapshotUrl=https://artifactory.website.com/artifactory/libs-snapshot-local/; \
index=${.}/release.maven; \
name="Maven Remote"
Looking in https://bnd.bndtools.org/instructions/connection-settings server auth configuration for bnd differs from maven configuration (0.3.4, for some reason I missed that part)
<server>
<username>username</username>
<password>roigonsdnglosgnoisfgnsdjgnlafjksasgnl</password>
<id>https://*website.com</id>
</server>
and bnd is looking for connection settings first in .bnd, if there are none, then in .m2, but if there are incorrect/insufficient settings in .bnd it does not look in .m2 even if it contains correct/sufficient ones.
The default order in which bnd looks for settings is:
`~/.bnd/connection-settings.xml`
`~/.m2/settings.xml`

How to get all remote repositories of a maven project hierarchy?

I'm redirecting all maven repository access to an Artifactory with the following ~/.m2/settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- unclear what version changes -> use 1.1.0 because it's higher -->
<servers>
<server>
<id>central</id>
<username>admin</username>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
</server>
</servers>
<mirrors>
<mirror>
<id>artifactory</id>
<name>artifactory</name>
<mirrorOf>*</mirrorOf>
<url>https://[hostname]:[port]/artifactory/remote-repos/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>artifactory</id>
<repositories>
<repository>
<id>central</id>
<name>remote-repos</name>
<url>https://[hostname]:[port]/artifactory/remote-repos</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>interval:25200</updatePolicy>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<name>remote-repos</name>
<url>https://[hostname]:[port]/artifactory/remote-repos</url>
<snapshots />
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>remote-repos</name>
<url>https://[hostname]:[port]/artifactory/remote-repos</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>interval:25200</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<name>remote-repos</name>
<url>https://[hostname]:[port]/artifactory/remote-repos</url>
<snapshots />
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
and thus have to add extra remote repositories which are specified by a project (and its child projects) to the Artifactory instance. I currently use
find . -name pom.xml -exec grep -B 5 -C 5 '<repository>' {} +
which isn't very handy in case an URL is a variable and declared elsewhere and it doesn't skip duplicates. It's not the worst thing in the world, but maybe there's an improvement available.
The following doesn't work:
mvn versions:display-dependency-updates doesn't display remote repositories
mvn dependency:list-repositories only works until the first dependency can't be fetched if the proxy is enabled so that I have to figure out where to get it from, add the researched remote repository to Artifactory or move ~/.m2/settings.xml aside - less handy than the find command above
The solution should work recursively, i.e. include all repositories in all child projects and childrens child projects, etc.
It makes a lot of sense that a solutions don't require to download the dependencies directly from the remote repository first without the proxy since I'd like to transfer them through the Maven proxy immediately if possible - it's not a requirement, though.
A somewhat hacky approach could be those two steps:
Get the effective POMs. Note that the below goal generates an XML file containing all POMs at once. However, variable names will already be resolved.
mvn help:effective-pom -Doutput="effective-pom.xml"
Parse the resulting XML file and gather the repositories, e.g., using a Python script gather-repos.py.
#!/usr/bin/python
import sys, xml.etree.ElementTree as ET
root = ET.parse('effective-pom.xml').getroot()
repositories = dict()
for node in root.iter('{http://maven.apache.org/POM/4.0.0}repository'):
repo_id = node.findtext('{http://maven.apache.org/POM/4.0.0}id')
repositories[repo_id] = node
for node in repositories.itervalues():
ET.ElementTree(node).write(sys.stdout, default_namespace='http://maven.apache.org/POM/4.0.0')
Of course, the script can then be run via
chmod +x gather-repos.py
./gather-repos.py

Nexus is not caching maven central plugins

Im using Maven 3.0.4 and Nexus 2.0.6. I have set up my settings.xml as the Nexus instruction show for using a single repository.
I get the error below when maven tries to run maven -U clean.
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its d
ependencies could not be resolved: Failed to read artifact descriptor for org.ap
ache.maven.plugins:maven-clean-plugin:jar:2.4.1: Could not find artifact org.apa
che.maven.plugins:maven-clean-plugin:pom:2.4.1 in nexus (http://localhost:8081/n
exus/content/groups/public) -> [Help 1]
If I remove the nexus mirror from the settings and go directly to maven central the command works. The settings for the maven repo in nexus show that it is in service and it is in the public group (its listed last).
I am not behind a proxy to access the internet.
Here is my settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<offline>false</offline>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>maven-central</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Make sure the Central proxy repository is properly configured, and the proxied URL is http://repo1.maven.org/maven2/. Check that you can see cached artifacts at the repository's URL, should be http://localhost:8081/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.4.0/maven-clean-plugin-2.4.1.pom.
Make sure you have a Central proxy at all, is there anything listed at http://localhost:8081/nexus/content/repositories/central/.
If you're behind a proxy, you can configure the proxy under the Default HTTP Proxy Settings (optional) section in the Administration->Nexus pane.
Then, make sure the Public Repositories group repository is configured to include the Central repository in its list of included repositories.
If everything looks fine so far, check the logs, maybe there's a helpful message in there.
Try downloading this directly through a web browser:
http://localhost:8081/nexus/content/groups/public/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
If this doesn't work check the sonatype-work/nexus/logs/nexus.log file for more information about the failure.
I had the same symptom as the OP (Nexus was not mirroring an artifact) and found that it was caused by a route definition.
For example, you have an artifact org.blabla:blabla-api:1.0 which is in Maven Central. However you have set up a route matching .*/org/blabla/.* that forces any matching requests to look only in the proxied repository blabla-public ... but unfortunately blabla-public doesn't contain that particular artifact.
Solution: either update the route to add Central to the list of repos used by the route, or delete the route.
(This probably wasn't the cause for the OP, but I'm posting it in case it helps any other visitors.)

The authorization of the Artifactory in Jenkins does not work

I´m using Artifactory 2.4.0 and Jenkins 1.438 and I have maven project with several modules. Need to deploy all modules(jars and one resulting war)
into remote Artifactory server by Jenkins.
My user admin for artifactory was with default password (password) and all builds that I tried to execute on jenkins works fine. So when I resolved
to change de Artifactory admin password and update my settings with the new credentials of admin, I had the following error on jenkins build log:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project pilotoExemplo: Failed to deploy artifacts:
Could not transfer artifact br.com.pilotoExemplo:pilotoExemplo:pom:2.1.0.11-20120705.160113-1 from/to snapshot
({ip_server}/artifactory/libs-snapshot-local): Failed to transfer file:
{ip_server}/artifactory/libs-snapshot-local/br/com/pilotoExemplo/pilotoExemplo/2.1.0.11-SNAPSHOT/pilotoExemplo-2.1.0.11-20120705.160113-1.pom.
Return code is: 401
Anyone already saw this problem before? I don´t found anything like this search on the google.
Here is my settings.xml:
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>repositorio</name>
<url>{ip_server}/artifactory/repo</url>
<id>repositorio</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>{ip_server}/artifactory/libs-release/</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>{ip_server}/artifactory/libs-snapshot/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>{ip_server}/artifactory/plugins-release</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
<distributionManagement>
<repository>
<id>release</id>
<url>{ip_server}/artifactory/libs-release-local/</url>
</repository>
<snapshotRepository>
<id>snapshot</id>
<url>{ip_server}/artifactory/libs-snapshot-local/</url>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
<servers>
<server>
<id>snapshot</id>
<username>admin</username>
<password>newPassword</password>
</server>
<server>
<id>release</id>
<username>admin</username>
<password>newPassword</password>
</server>
<server>
<id>repositorio</id>
<username>admin</username>
<password>newPassword</password>
</server>
</servers>
As far as I know Jenkins jobs can have their own M2 repository, or they use the repository of the user. So the answer could be, that your jenkins is running as a service (maybe as local system account), and not in the name of your user.
You can check the user name at the Jenkins setting/system information page (yourcontextroot/systemInfo). So basicly the solution is to put the same settings file for the running user, like you have.
Tip to solve the problem with the clear text password:
Access and login into Artifactory.
Once you are logged in, click over your user name, on the superior right corner of the screen.
Put your password then clique in the em Unlockbutton, enabling the encrypted password.
Copy the tag that will be showed on the inferior part of the screen and paste it into the settings.xml file. If you prefer to just copy the password, be sure about let it exactly equals the tag showed below, including the "\" at the beginning of the password.
Remember to adjust the tag with the id of your server, defined into the tag, in your POM.xml
Click in Update button and ready! Check if everything will occur well at the next project's publication.

Maven deploy error

I have maven project with several modules. Need to deploy all modules(jars and one resulting war) into remote Artifactory server.
So in settings.xml I am added config:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>admin</username>
<password>password</password>
<id>central</id>
</server>
<server>
<username>admin</username>
<password>password</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<id>central</id>
<name>libs-release</name>
<url>http://192.168.1.120:8088/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://192.168.1.120:8088/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://192.168.1.120:8088/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://192.168.1.120:8088/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
Main pom have section:
<distributionManagement>
<repository>
<id>central</id>
<url>http://192.168.1.120:8088/artifactory/libs-release-local</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.1.120:8088/artifactory/libs-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
And all modules have 1.0-SNAPSHOT version.
But when executing the command: >mvn deploy, the Following error occured:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
(default-deploy) on project jobic: Failed to deploy artifacts: Could
not transfer artifact *project-name:project-nam*e:pom:0.0.1 from/to central
(http://192.168.1.120:8088/artifactory/libs-release-local): Failed to
transfer file:
http://192.168.1.120:8088/artifactory/libs-release-local/project-name/project-name/0.0.1/project-name-0.0.1.pom.
Return code is: 401 -> [Help 1]
How to deal with it?
UPDATE:
Ok, I got it. The 401 error says: 401 = "Unauthorized" . So I added proper username/password into settings.xml. Seems work now.
Have one last question: it is right, that I am using SNAPSHOT suffix in the version? Is it proper behavior for situation, when I need do deploy all modules onto remote repo? How to deal with situation, when the one module was broken and my coworkers need to use previous version of this module?
It might be because it is written incorrectly.
You can change it hhttp to http and try again.

Resources