Maven build error because of an unresolved Maven POM property used in repository URL when specifying Spring's bill-of-material POM - maven

I'm facing a reproducible strange behavior when referencing a Maven POM property in the POM's repositories section and having a bill of materials POM (here Spring-Framework-BOM) defined.
Setup to reproduce the problem:
Maven 3.0.5, JDK 1.7.0.51.x86_64
Maven POM with a property that holds my Nexus-URL prefix
that property is referenced in the pluginRepositories and repositories section
additionally having spring-framework-bom dependency in dependencyManagement section defined
The build error occurring in the log:
[ERROR] Non-resolvable import POM: Could not transfer artifact org.springframework:spring-framework-bom:pom:4.0.3.RELEASE from/to mycompany.public (${nexus.baseUrl}/content/groups/public/): No connector available to access repository mycompany.public (${nexus.baseUrl}/content/groups/public/) of type default using the available factories WagonRepositoryConnectorFactory # line 692, column 16
Here the excerpt from my Maven POM file:
<properties>
<nexus.baseUrl>http://nexus.mycompanydomain.com</nexus.baseUrl>
<spring.version>4.0.3.RELEASE</spring.version>
</properties>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<url>${nexus.baseUrl}/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>mycompany.public</id>
<name>MyCompany Public Repository</name>
<url>${nexus.baseUrl}/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Hotfix
I could solve the problem by replacing the nexus.baseUrl by it's value in the repositories section of the POM:
<repository>
<id>mycompany.public</id>
<name>MyCompany Public Repository</name>
<url>http://nexus.mycompanydomain.com/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
Question
Is anyone able to explain why the resolution of the nexus.baseUrl property is not taking place while the spring.version property is resolved successfully (see error log)?

IMHO the the problem lies in the order of evaluation of the pom.
Properties, like in your case, the property "nexus.baseUrl" are not getting evaluated before the import scope is getting triggered.
In my case, replacing property reference (nexus.baseUrl) in the repository url element with the concrete url solved the problem.

Related

3rdparty repository issues with maven pom.xml

I was looking for BIRT Dependency in the net. Package my code refers are
import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.attribute.Anchor;
It is using chartengineapi and below is the maven dependency entry for POM.
<!-- https://mvnrepository.com/artifact/org.eclipse.birt/chartengineapi -->
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>chartengineapi</artifactId>
<version>2.3.2</version>
</dependency>
Since it is part of other repository (https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/) it gives error in Pom.xml. Could any one help me to sort out this ?
added repository tag and resolved.
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
Add one more <repository></repository> and the give the new repo name and link. It worked for me though I am not sure whether this is a standard approach.

spring-security-saml missing jar in repo

As per the instructions on http://projects.spring.io/spring-security-saml/, I have the following in my pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml</artifactId>
<version>1.0.0.RC2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
When I execute mvn clean install -U, I receive the following error:
[ERROR] Failed to execute goal on project myproj: Could not resolve dependencies
for project com.acme.myproj:myproj:war:1.0.0-SNAPSHOT: Could not find artifact org.
springframework.security.extensions:spring-security-saml:jar:1.0.0.RC2 in spring
-milestones (http://repo.spring.io/milestone) -> [Help 1]
The repo is there at http://repo.spring.io/milestone/org/springframework/security/extensions/spring-security-saml/1.0.0.RC2/, but there is no .jar file.
The correct dependency to use is:
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
The jar is available both in Maven Central and http://repo.spring.io/list/release/
The Spring SAML web will get fixed soon.

Maven uses wrong repository to lookup dependencies

In my settings.xml I declared a custom repository in a profile like this:
<servers>
<server>
<id>server.id</id>
<username><uname></username>
<password><pw></password>
</server>
</servers>
<profiles>
<profile>
<id>dev.id</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>repo.id</id>
<url>valid working url</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
what works great for all dependencies located there, but build fails whenever I declare dependencies which are located in the central repository. For instance:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
results in:
[ERROR] Failed to execute goal on project <name>: Could not resolve dependencies for project…
…Failed to read artifact descriptor for junit:junit-dep:jar:4.9.1-SNAPSHOT: Could not transfer artifact junit:junit-dep:pom:4.9.1-SNAPSHOT from/to <server.id>…
How can I make maven load dependencies correctly?
You are trying to use a -SNAPSHOT dependency which is not available in Maven Central.
junit:junit-dep:jar:4.9.1-SNAPSHOT: Could not transfer artifact junit:junit-dep:pom:4.9.1-SNAPSHOT fr
In Maven central there are only releases available.
Furthermore the above dependency is not coming into your build by the junit:junit:4.11:jar dependency it must be comming from other sources.

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.

The POM for org.springframework.security:org.springframework.security.web:jar:3.0.5.RELEASE is missing, no dependency information available

When including into pom.xml
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>org.springframework.security.web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
with repositories
<repository>
<id>com.springsource.repository.bundles.milestone</id>
<name>EBR Spring Milestone Repository</name>
<url>http://repository.springsource.com/maven/bundles/milestone</url>
</repository>
<repository>
<id>org.springframework.maven.milestone</id>
<name>Maven Central Compatible Spring Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>EBR Spring Release Repository</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>EBR External Release Repository</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
I get the following error message when doing the maven build:
The POM for org.springframework.security:org.springframework.security.web:jar:3.0.5.RELEASE is missing, no dependency information available
Other spring libraries are included well. What's going wrong? Thank you for any help.
Update
I simplified pom.xml to
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0.1</version>
<name>test</name>
<url>http://test</url>
<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>org.springframework.security.web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>com.springsource.repository.bundles.milestone</id>
<name>EBR Spring Milestone Repository</name>
<url>http://repository.springsource.com/maven/bundles/milestone</url>
</repository>
<repository>
<id>org.springframework.maven.milestone</id>
<name>Maven Central Compatible Spring Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>EBR Spring Release Repository</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>EBR External Release Repository</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
</repositories>
</project>
and when calling mvn -U install (forces update check) it gives
[ERROR] Failed to execute goal on project test: Could not resolve dependencies for project test:test:jar:1.0.1: Could not find artifact org.springframework.security:org.springframework.security.web:jar:3.0.5.RELEASE in com.springsource.repository.bundles.milestone (http://repository.springsource.com/maven/bundles/milestone)
I see that the repository is properly populated, so the problem is a wrong artifactId. It's spring-security-web, not org.springframework.security.web.
You are using the wrong artifactId. Use this:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
And you don't need any custom repositories, you can find it in Maven Central.
http://static.springsource.org/spring-security/site/petclinic-tutorial.html gives a wrong artificact Id where I copied the dependency from. Interestingly it works with version 3.0.3.RELEASE but not with 3.0.5.RELEASE.
Thanks for the hint Sean, I updated the answer.

Resources