Maven issue while installing Spring project - spring

Attended Spring Core training recently. When I installed the projects after the course and converted the projects as a Maven project, I get the following error.
Project build error: Non-resolvable parent POM: The repository system is offline but the artifact com.springsource.training.core-spring:parentCoreSpringProject:pom:
4.0.0.CI-SNAPSHOT is not available in the local repository. and 'parent.relativePath' points at wrong local POM
I tried adding relative-path too, but it did not help.
<parent>
<groupId>com.springsource.training.core-spring</groupId>
<artifactId>parentCoreSpringProject</artifactId>
<version>4.0.0.CI-SNAPSHOT</version>
</parent>

The message is pretty clear - the pom points to a repository that you don;t have access to.
Either get access, or change the repository it points to.
(maven downloads required dependencies(jar files) from a server and apparently you don't have access to specified server but you can use public servers/repositories instead)

Related

Missing artifact in pom.xml

I'm facing a problem in the pom.xml. It is showing the below error. I'm trying to update maven by adding the required dependencies but unable to solve the issue .
Resource Path Location Type Missing artifact org.springframework.security:spring-security-web:jar:4.2.2.BUILD-SNAPSHOT pom.xml /spring-security-samples-xml-insecure line 171 Maven Dependency Problem
SNAPSHOT dependencies are not retrieved by default. If you really need that specific version you will need to add the spring snapshot repository to maven. Usually one relies on released versions only: maven central
The version you are looking for is in the spring snapshots repository.
The maven manual describes how to work with multiple repositories. Usually people use a repository proxy like Nexus or Artifactory to simplify this.

_remote.repositories prevents maven from resolving remote parent

I have my company parent pom in releases repository on a company Nexus instance.
I have mirror settings of <mirrorOf>external:*,!central</mirrorOf>, I don't want to proxy central since our Nexus is a bit slow.
When I have a maven project, with parent set like:
<parent>
<groupId>com.acme.maven</groupId>
<artifactId>parent-pom</artifactId>
<version>2</version>
<relativePath />
</parent>
and the parent-pom project is not available in local repository the build will fail -- this is as expected so far.
However if I download the parent-pom using dependency:get goal, the pom file gets downloaded to local repository. However when I try to build the project it fails with:
[exec] [ERROR] The project com.acme:test:0.0.1-SNAPSHOT (/home/acme/pom.xml) has 1 error
[exec] [ERROR] Non-resolvable parent POM: Failure to find com.acme.maven:parent-pom:pom:2 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at no local POM # line 5, column 13 -> [Help 2]
Now if I remove the _remote.repositories file (and only that file) from .m2/repository/com/acme/maven/parent-pom/2/ the build will succeed.
I have some kind of a workaround, but manually removing internal files from maven repository doesn't sound like a good idea. How can avoid it?
Also I have no idea why is this happening, some explanation will be much appreciated.
Other approaches:
maven-ant tasks dependencies task works (_remote.repositories file doesn't appear at all)
trying to build with -U
using dependency:copy fails
using dependency:list on a pom.xml having the parent-pom as dependency also fails
_remote.repositories content:
#NOTE: This is an Aether internal implementation file, its format can be changed without prior notice.
#Mon Sep 14 19:59:41 CEST 2015
parent-pom-2.pom>internal-repo=
I think the answer is here:
Maven 3.0+ enforces that downloaded artifacts were resolved from a
repository url/id that matches an url available for the current
session.
..
IIRC there is a CLI option that you can enabled in Maven 3.1.1 that
tells Maven "I know what I am doing and don't make that check this
time" i.e.
--legacy-local-repository
Indeed adding --legacy-local-repository to the dependency:get invocation makes it not produce the _remote.repositories, and the parent-pom can be resolved.
Ant's dependencies task behaviour can, I think, be explained by it using Maven 2 code.

Is there a way to say maven not to use timestamp for dependency resolution

I am using MAVEN3 and I have a project XXX with version 1.0.0-SNAPSHOT and it is being uploaded to artifactory.I can find the jar uploaded to artifactory as XXX-1.0.0-SNAPSHOT.jar.
Another project YYY uses XXX-1.0.0-SNAPSHOT.jar as its dependency and it is declared as
<dependency>
<groupId>...<...>
<arti...>XXX</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
When I try to build YYY maven is trying to download XXX jar file from artifactory and it fails to find.
I get the following error
Could not resolve dependencies for project com......YYY:jar:1.0.0-SNAPSHOT: Could not find artifact com....XXX:jar:1.0.0-20130710.163046-1 in repo1 (https://artifactory.xxx.com/artifactory/REPO1)
I can see that it tries to download a jar with specific timestamp.How can I tell maven not to use timestamp to download my dependency.
Any help on this is appreciated.
Support for non-unique snapshots was removed in Maven 3 (see related JIRA issue).
I found an Artifactory document mentioning one way to handle this, near the bottom of the page.
My team has noticed problems if developers publishing snapshots to the same group/artifact in the snapshot repository are not all using the same Maven version. Either everyone needs to stick with Maven 2, or everyone uses Maven 3. Mixing doesn't work well.

How does my pom find my parent pom if the repositories are configured in the parent pom?

I've refactored all repository configuration out of my various projects into a parent pom that I've created for the specific purpose of having a single point of configuration for stuff like repo's and distribution management. This is supposed to be best practice as I understand it. In deployed my parent pom to the nexus server, and then tried to run my child projects. They can't find my parent pom . . . this kind of makes sense to me since, wihtout the parent pom they don't know about the nexus repo . . . seems like a chicken and egg kind of thing? Am I missing something obvious?
It's true that your project needs to know where to find the repositories to download its dependencies. But before going to external repositories, Maven will check your local repository to see if the artifacts it needs are in there. Does your local repository contain the parent pom? If not, you can add it by running
mvn install
on the parent pom. The problem may have been caused by deploying the parent pom directly to Nexus, bypassing your local one. You can avoid this in future by deploying using
mvn deploy
This will first install the artifact locally, and then deploy it to the external repository (Nexus, in your case). More details here: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
If you're in a situation whereby your parent pom is built and deployed by others, this won't help. You can either specify the repositories in your project's pom, or in your local settings.xml. A common approach is to expect all developers to include a repository definition in their local settings.xml which points to your Nexus repository, using it as a mirror for all other repositories. You can then configure each external repository you need in Nexus, and let it retrieve any dependencies you need for you. I'm not familiar with Nexus, but more details on mirroring can be found here: http://maven.apache.org/guides/mini/guide-mirror-settings.html
You must maintain the repositories definitions for each child (maven module), this is main best practice in a build process: "Make the build portable".
Any developer/system should be able to build any module without source dependencies to the parent or other modules, only with the repository reference.

How do I add an artifact to a local maven repository so that it will properly reference its own set of dependencies?

I am developing an application that depends on a number of legacy JAR files and I want the project to build straight out of version control without other users having to install these JARs in their local repository. I cannot add them to the corporate repository so I have created a repository that is local to this project and I have added these JARs to that repository using maven-install-plugin:install-file and setup the repository entry in the POM file so it knows to search the local repository.
This works exactly the way I want...up to a point. The problem is that most of these legacy JAR files have their own set of dependencies. I would like for them to work just like other artifacts that have their own set of dependencies so that maven can resolve everything and include all the necessary files but I can't find a way to do this with any maven-install-plugin:install-file options (or any other maven commands/plugins). I am pretty new at maven so I am probably just ignorant on this point.
As a work around, I attempted to go into the local repository directory and manually edit the POM file for the artifact to include the dependencies. This didn't cause any errors but it is also not pulling in those dependencies.
Can someone out there give me a clue?
The maven-install-plugin:install-file goal has a pomFile attribute. You can use this to specify a POM file for your legacy jar. You would create a POM file that points to all of the dependencies by artifactId in the <dependencies> section. If you have a remote nexus repository you can use the admin screen for the repository to deploy a jar.
Once you edit POM files in your project specific repository, host it as maven repo using Maven Repository Managers (like sonatype nexus). Add your project nexus repo as one of the maven repo in project pom.xml as below
<repositories>
<repository>
<id>my-project-mvn-repo</id>
<name>my-project-mvn-repo</name>
<url>http://<your project maven repo URL here></url>
</repository>
<repositories>
Now all developers should be able to make build. The legacy jar files POM contains dependency. Maven should take care of automatically pulling dependent jars on developer's workspace.

Resources