How to resolve outdated repository informations in a pom? - maven

I have a legacy application that I'm trying to build using maven 2.
The build currently fails with the message
Unable to get dependency information: Unable to read the metadata file for artifact 'com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar': Cannot find parent: org.sonatype.oss:oss-parent for project: com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.2 for project com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.2
com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.2
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
The application has a dependency on concurrentlinkedhashmap 1.2. However this artifact specifies the following in its pom.xml:
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>3</version>
</parent>
...
<repositories>
<repository>
<id>sourceforge</id>
<url>http://oss.sonatype.org/content/groups/sourceforge/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
...
</repositories>
Now when looking at the specified repository, the dependency isn't contained in there.
However the parent dependency is available in maven central.
What do I need to do, that the dependency gets downloaded from maven central instead?

If the artifact is now contained in another repo, a mirror can be defined in the maven settings to point maven to the repo that now contains the artificat.
<mirror>
<id>sourceforge-mirror</id>
<name>Sourceforge Mirror</name>
<url>http://repo1.maven.org/maven2</url>
<mirrorOf>sourceforge</mirrorOf>
</mirror>
However this won't work if the source of the mirror contains some artifacts, that the target of the mirror doesn't.

Related

Maven dependencies from internal and central repository

I have an internal Nexus repository in Maven where some plugins are deployed. There are some dependency jar file that are not present in the nexus repository while some are there. Is it possible to configure maven to search for the dependency jar files in internal repository and if not present search in the maven central repository.
Update
Made the similar configuration as in answer of JimHawkins. But still I guess its looking only in the nexus internal repositories for the dependencies. Here are some of the debus messges it prints:
[DEBUG] Using mirror Nexus (<internal-repo>) for central (repo1.maven.org/maven2).
[DEBUG] Using mirror Nexus (<internal-repo>) for Nexus (my.repository.com/repo/path)
[ERROR] Unresolveable build extension: Plugin <plugin-name> or one of its dependencies
could not be resolved: Failure to find org.co dehaus.plexus:plexus-utils:jar:1.1 in <internal-repo>
was cached in the local repository
If you modify your personal maven settings.xml (located in <HOME>/.m2) like shown below, maven searches your Nexus for dependencies, instead of looking in maven central rpository. If maven doesn't find them in Nexus, Nexus will download them from the maven central repository and than provide it to maven.
Every dependency is also stored in your local maven repository on your workstation, after maven fetched it from Nexus
You can tell Nexus to search for new artifacts not only in maven central repository, but also in other public repos (such as JBoss public repository).
See also: Maven configuration
Use these settings in settings.xml:
<mirrors>
<!--
mirror | Specifies a repository mirror site to use instead of a
given repository. The repository that | this mirror serves has an ID
that matches the mirrorOf element of this mirror. IDs are used | for
inheritance and direct lookup purposes, and must be unique across
the set of mirrors. | <mirror> <id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this
Mirror.</name> <url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://your.internal-nexus.com/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<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>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>

Retrieving dependencies from maven repository

So for my maven project I require jar dependencies that are available in public repositories and also jar dependencies that are on our company internal repository.
How do I configure my pom.xml so that I will retrieve the dependencies from public repositories and our company internal repository without synchronizing and uploading the stuff from public repos to the company internal repository.
In your settings.xml, which is usually in HOME_DIR/.m2 you need to add the company repository, maven central is included by default.
In the example below it will look for your artifact in each repo in order, starting with maven central.
<profile>
<id>extras</id>
<repositories>
<repository>
<id>release</id>
<name>libs-release</name>
<url>http://internal.corp:8091/artifactory/libs-release</url>
</repository>
<repository>
<id>snapshot</id>
<name>libs-snapshot</name>
<url>http://internal.corp:8091/artifactory/libs-snapshot-local</url>
</repository>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
<repository>
<id>spring-milestone</id>
<name>Spring Maven MILESTONE Repository</name>
<url>http://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
</profile>
I would also say that I set up our corporate repository so that is has a virtual repository to maven central. This means as people use artifacts they will be stored in the company repository. This is normal practice.

How do you configure maven to ignore repositories specified in POM files?

I have a project on a company intranet (read - no outside internet access). I have a server running Artifactory with all required maven artifacts. I have a settings.xml file pointing maven to the running Artifactory server. Everything is happy and maven can download dependencies until an artifact specifying a repository in the POM file (in my case org/eclipse/jetty/jetty-project/7.5.4.v20111024/jetty-project-7.5.4.v20111024.pom). Then maven attempts to load the remaining dependencies from the repo specified in the POM file instead of from Artifactory. This breaks the build. How do you configure maven to ignore repositories specified in POM files?
Thanks,
Nathan
As a workaround, define another repository in your settings.xml with the same ID (is it oss.sonatype.org, defined in jetty-parent:19, that's the problem?) and point it at your repo. Maven will use that definition in favour of the one in the pom.
There's an open issue filed against Maven (MNG-3056) to allow this to be configured so only your repo would be used; in general, if you have a local repository, that would be the behaviour you would want.
That's a great answer Joe. Thank you. I was looking for it for quite some time.
I just quote an example, in which I had the same problem as Nathan.
I use a Maven enterprise repository (Nexus or Artifactory) and I am behind a proxy, that means that I cannot download directly (and do not want to) from any other repositories than mine.
Jasper reports net.sf.jasperreports:jasperreports:6.2.0 defines in its pom a couple of repositories.
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.2.0</version>
...
<repositories>
<repository>
<id>jasperreports</id>
<url>http://jasperreports.sourceforge.net/maven2</url>
</repository>
<repository>
<id>jaspersoft-third-party</id>
<url>http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/</url>
</repository>
</repositories>
This causes the following exception:
C:\my-project>mvn verify
[INFO] Scanning for projects...
[INFO] Building my-project 1.0.0-SNAPSHOT
[INFO]
Downloading: http://mynexus/nexus/content/groups/ch-public/com/lowagie/itext/2.1.7.js4/itext-2.1.7.js4.pom
Downloading: http://jasperreports.sourceforge.net/maven2/com/lowagie/itext/2.1.7.js4/itext-2.1.7.js4.pom
Downloading: http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/com/lowagie/itext/2.1.7.js4/itext-2.1.7.js4.pom
[INFO] BUILD FAILURE
[INFO] Could not resolve dependencies for project ... :
Failed to collect dependencies at net.sf.jasperreports:jasperreports:jar:6.2.0 ->
com.lowagie:itext:jar:2.1.7.js4: Failed to read artifact descriptor for com.lowagie:itext:jar:2.1.7.js4:
Could not transfer artifact com.lowagie:itext:pom:2.1.7.js4
from/to jasperreports (http://jasperreports.sourceforge.net/maven2):
Connect to jasperreports.sourceforge.net:80 [jasperreports.sourceforge.net/216.34.181.96]
failed: Connection timed out:
The solution as described by Joe is:
In global settings.xml (C:/maven-installation/conf/settings.xml) or private settings.xml (~/.m2/settings.xml) add the following profile:
<profiles>
<profile>
<id>ignore-repositories</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<repositories>
<repository>
<id>jasperreports</id>
<url>http://mynexus/nexus/content/groups/ch-public/
</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jaspersoft-third-party</id>
<url>http://mynexus/nexus/content/groups/ch-public/
</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
Important: the repository id in the profiles (jasperreports , jaspersoft-third-party) matches exactly the id of the repository used in pom.xml - in this case the pom.xml of net.sf.jasperreports:jasperreports:6.2.0
Do not forget to add the "external" repositories to the "proxy" list of your Maven Enterprise Repository

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>

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