Not Downloading Jars from Release version - java

My nexus repository are defined as following
maven-release - which contains my customer jars
maven-snapshots - which contains my project jars
and my settings xml file as bellows:
<repository>
<id>nexus</id>
<name>nexus-repo-snapshots</name>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>https://nx0.my.biz/repository/maven-snapshots</url>
<layout>default</layout>
</repository>
<repository>
<id>nexus</id>
<name>nexus-repo-release</name>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
<url>https://nx0.my.biz/repository/maven-releases</url>
<layout>default</layout>
</repository>
and my distributed management is as bellows:
<distributionManagement>
<repository>
<id>nexus</id>
<name>Releases</name>
<url>${nexus.url}/repository/maven-releases</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Snapshot</name>
<url>${nexus.url}/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>
I have uploaded my custom jars in maven releases
now what is happening that It is downloading jars from maven-snapshots only like
Downloading from nexus: https://nx0.my.biz/repository/maven-snapshots/com/my/custom/2.4.0/custom-2.4.0.jar
and giving error while building that
Could not find artifact com.my:custom:jar:2.4.0 in nexus (https://nx0.my.biz/repository/maven-snapshots)
Please let me know if I am doing anything wrong.

check your maven settings.xml.
if you set two mirror and both of them mirrorOf attribute been set to *,then maven will use the first mirror to download all the dependencies.
that almost killed my whole day.

The distributionManagement section of your pom is only used for uploading artifacts with either the deploy goal to the snapshot repository or the maven release plugin to the release repository.
The repositories section of your settings.xml will be used to download artifacts to your local repository (usually ~/.m2).
The repositories will be looked at in the order they are given in the settings.xml.

Related

Maven artifact cannot be resolved; attempting to resolve artifact from the wrong repository

After upgrading a dependency in my pom.xml, I received the following error when attempting to download the new artifact (Using maven command line mvn spring-boot:run in this case).
The following artifacts could not be resolved:
io.github.bonigarcia:webdrivermanager:jar:3.8.1,
org.zaproxy:zap-clientapi:jar:1.7.0: Could not find artifact
io.github.bonigarcia:webdrivermanager:jar:3.8.1 in spring-milestone
(https://repo.spring.io/milestone)
The error message is correct, that artifact does not exist in https://repo.spring.io/milestone. It does exists in Maven central (https://repo.maven.apache.org/maven2), so why would Maven be looking for the artifact in the wrong repository?
I do know that this is tied to my Maven settings (settings.xml) where I define a mirror to our internal Nexus repository. When I remove the mirror, Maven successfully looks for and finds the artifact in Maven central. What I don't understand is the mechanics of how things work when an artifact does not exist in Nexus, and why this mirror setting changes how an artifact is discovered for the first time.
From settings.xml..
<mirrors>
<mirror>
<id>Nexus</id>
<name>Nexus Public Mirror</name>
<url>https://myinternalnexushost.net/nexus/content/repositories/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
It's also noteworthy that this is a Spring Boot project. I don't define any repositories in my pom.xml, but since I'm specifying a spring boot parent pom I'm inheriting the following repositories:
From Spring Boot parent pom
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>spring-milestone</id>
<name>Spring Milestone</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>spring-snapshot</id>
<name>Spring Snapshot</name>
<url>https://repo.spring.io/snapshot</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>rabbit-milestone</id>
<name>Rabbit Milestone</name>
<url>https://dl.bintray.com/rabbitmq/maven-milestones</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
You usually define the repos under repositories and each of it has an identifier. This identifier is then used for the mirrors. In your config you mirror the repo with id central
<mirrors>
<mirror>
<id>Nexus</id>
<name>Nexus Public Mirror</name>
<url>https://myinternalnexushost.net/nexus/content/repositories/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
As the repo https://repo.spring.io/ has another identifier it is not mirrored using central. So you have to define mirrors for each other repos as well, for example
<mirrors>
<mirror>
<id>Nexus</id>
<name>Nexus Public Mirror</name>
<url>https://myinternalnexushost.net/nexus/content/repositories/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>Spring</id>
<name>Nexus Public Mirror</name>
<url>https://myinternalnexushost.net/nexus/content/repositories/spring-milestone</url>
<mirrorOf>spring-milestone</mirrorOf>
</mirror>
</mirrors>
See also the guidelines:
With Repositories you specify from which locations you want to download certain artifacts, such as dependencies and maven-plugins. Repositories can be declared inside a project, which means that if you have your own custom repositories, those sharing your project easily get the right settings out of the box. However, you may want to use an alternative mirror for a particular repository without changing the project files.
I generally would do the following which makes things a bit easier to maintain
create a "remote" repo for each of the required repos in Nexus
create a "group" repo in Nexus which contains all remote repos
then you have to specify only this in your settings.xml
<mirrors>
<mirror>
<id>Nexus</id>
<name>Nexus Public Mirror</name>
<url>https://myinternalnexushost.net/nexus/content/repositories/maven-group</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
When you tell Maven to use a mirror, that mirror is used instead of the original repository.
Which means when you mirror "central" you lose access to anything in Maven Central that's not in that mirror.

Different repository in DistributionManagement and Repositories

In <DistributionManagement> ... </DistributionManagement>
and <Repositories> ... <Repositories> sections, there can be a
<Repository> ... </Repository>
definition. What's the difference between the two definition? This is one example:
<distributionManagement>
<downloadUrl>https://github.com/marytts/marytts/releases</downloadUrl>
<repository>
<id>bintray</id>
<url>https://api.bintray.com/maven/marytts/marytts/marytts</url>
</repository>
<snapshotRepository>
<id>bintray</id>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
And
<repositories>
<repository>
<id>marytts-dependencies</id>
<name>marytts-dependencies</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.local.repository.path}</url>
</repository>
<repository>
<id>central</id>
<name>jcenter</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
Distribution Management
Distribution management acts precisely as it sounds: it manages the
distribution of the artifact and supporting files generated throughout
the build process. Starting with the last elements first:
Repository
Where as the repositories element specifies in the POM the location
and manner in which Maven may download remote artifacts for use by the
current project, distributionManagement specifies where (and how) this
project will get to a remote repository when it is deployed. The
repository elements will be used for snapshot distribution if the
snapshotRepository is not defined.
Deploy using the repository layout
To deploy your file using the maven layout you should define the distribution management location :
<project>
...
<distributionManagement>
<repository>
<id>myrepository</id>
<url>file:D:/repository/</url>
</repository>
</distributionManagement>
</project>
Then you just need to execute the following command to get you artifact copied in your file system location
Maven command to deploy a file in the local file system
mvn deploy
Site Distribution
More than distribution to the repositories, distributionManagement is
responsible for defining how to deploy the project's site and
documentation.
In pom.xml, configure where to deploy your site within distributionManagement tag.
<distributionManagement>
<site>
<id>mkyongserver</id>
<url>dav:http://127.0.0.1/sites/</url>
</site>
</distributionManagement>
Relocation
Projects are not static; they are living things (or dying things, as
the case may be). A common thing that happens as projects grow, is
that they are forced to move to more suitable quarters. For example,
when your next wildly successful open source project moves under the
Apache umbrella, it would be good to give your users as heads-up that
the project is being renamed to org.apache:my-project:1.0. Besides
specifying the new address, it is also good form to provide a message
explaining why.
Repositories
Repositories are collections of artifacts which adhere to the Maven
repository directory layout. In order to be a Maven repository
artifact, a POM file must live within the structure
$BASE_REPO/groupId/artifactId/version/artifactId-version.pom.
$BASE_REPO can be local (file structure) or remote (base URL); the
remaining layout will be the same. Repositories exist as a place to
collect and store artifacts. Whenever a project has a dependency upon
an artifact, Maven will first attempt to use a local copy of the
specified artifact. If that artifact does not exist in the local
repository, it will then attempt to download from a remote repository.
The repository elements within a POM specify those alternate
repositories to search.
The repository is one of the most powerful features of the Maven
community. The default central Maven repository lives on
http://repo.maven.apache.org/maven2/. Another source for artifacts not
yet in iBiblio is the Codehaus snapshots repo.
Be remember you can add only one <repository> and one <snapshotRepository> child inside <distributionManagement>
How to declare proxy
Just go to Maven-> conf-> setting.xml file and add proxy
<proxies>
<proxy>
<id>myproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>global.proxy.mycompany.com</host>
<port>8000</port>
<username></username>
<password></password>
<nonProxyHosts>localhost,127.0.0.1</nonProxyHosts>
</proxy>
</proxies>

SNAPSHOT and RELEASE versions are not getting update at Maven Local Repository

I had set up a Nexus Repository to link-up two separate projects. I am building and deploying the RELEASE and SNAPSHOT versions on Nexus successfully but when i am trying to use the changes in other project using maven update this changes are not getting updated.
So what I did in A_Project.jar in one Project which is got updated in nexus repository.
But when I am trying to get this updated jar at B_Project, I am getting the old jar which was there in maven's local repository. Now, if I manually delete the A_Project.jar, i apparently gets the updated code.
For achieving the updated version of SNAPSHOT and RELEASED version i had tried following ways.
I had used -U with mvn clean build.
I have changed the update policy in setting.xml and pom.xml as follows.
In settings.xml
<pluginRepository>
<id>deployment</id>
<name>Internal Nexus Repository</name>
<url>http://server/nexus/content/groups/public/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<updatePolicy>always</updatePolicy>
</releases>
</pluginRepository>
In pom.xml
<repositories>
<repository>
<id>snapshots</id>
<url>http://server/nexus/content/repositories/snapshots</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
Please help as this become a repeated process in getting the latest jar for me.
I can't see enough of your settings.xml to say what is going on. What you have shown is just the pluginRepository section, which is used for resolution of Maven plugins, not artifacts.
I'd suggest starting with a standard settings.xml file:
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html
You'll probably want to modify the central repository definition to always look for updates to snapshots:
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
It sounds like you are also trying to re-release the same release versions? This is a bad practice, releases should be considered immutable (and a lot of the toolchain assumes they are). Increment the version number to make a new release.

Cannot install any new libraries in Eclipse (Luna) Maven

This error just started appearing, with any new maven dependencies I install. The dependency shows up in the Maven dependencies tree empty, and the project reports, for example:
Description Resource Path Location Type Archive for required library: '~/.m2/repository/com/ning/async-http-client/1.8.14/async-http-client-1.8.14.jar' in project 'LB' cannot be read or is not a valid ZIP file LB Build path Build Path Problem
I viewed the POM file for each new dependency, and they all have this in them:
<HTML>
<BODY>
This repo has moved to repo.boundlessgeo.com. Please update your settings.
</BODY>
</HTML>
So i discovered that the OpenGeo Maven Repo has moved, based on this:
<!-- <repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>opengeo</id>
<name>OpenGeo Maven Repo</name>
<url>http://repo.opengeo.org</url>
</repository> -->
Replaced with this:
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
</repository>
Even though I fixed this issue, all other dependencies still fail to install. Any idea why the POM files for any other repo keep getting the HTML notice from OpenGeo? How can I fix?
Here's the entire repo section of my pom.xml
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repo</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repo</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>opengeo</id>
<name>OpenGeo Maven Repo</name>
<url>http://repo.opengeo.org</url>
</repository>
<repository>
<id>central</id>
<name>The Central Repository</name>
<url>http://repo1.maven.org/maven2/</url>
</repository>
Updated answer:
If you have a repository defined in your pom.xml which provides static content instead of a proper Maven repository (in this case http://repo.opengeo.org, which has moved to http://repo.boundlessgeo.org), Maven will download the static content as the pom, jar, etc and complain about it being corrupted later. These invalid files will remain in your local repository until you delete them, even after you fix the problem repository.
The simplest way to get rid of the invalid files would be to delete your entire ~/.m2/repository and download all artifacts fresh. However, you can also just delete the problem files (adjust the grepped message according to the static content in your invalid files):
grep -lrIZ "This repo has moved to repo.boundlessgeo.com" ~/.m2/repository \
| xargs -r0 rm
Then do a normal mvn clean install and valid artifacts should be downloaded from the corrected repository.
See the original question for details on updating http://repo.opengeo.org to http://repo.boundlessgeo.org.
Note: Maven is likely downloading the invalid static content because repo.opengeo.org is returning a status code of 200.
Original answer:
Is it possible that you've somehow configured the old OpenGeo Maven Repo to be a mirror for all respositories? Maybe in your local settings.xml, or in a Nexus artifact repository?
I ran into something similar, where our Nexus server somehow had a bunch of non-OpenGeo artifacts in our proxied OpenGeo repository. Once the OpenGeo/BoundlessGeo repo moved, I got the "This repo has moved" message until I deleted the non-OpenGeo artifacts from the proxy repository.

How do I get Maven to use the correct repositories?

I have just checked out some projects and need to build them, however I installed Maven quite some time ago (6 months maybe?) and really haven't used it since - the pom.xml for the project I have doesn't have this "http://repo1.maven.org/myurlhere" anywhere in it - it has the absolute url where the Maven repo is for the project, but Maven is still trying to download from the general Maven repo:
Macintosh:trunk$ mvn clean install
[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/url/project/project/x.x/project-x.x.pom
[INFO] Unable to find resource 'url.project:project:pom:x.x' in repository central (http://repo1.maven.org/)
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
GroupId: url.project
ArtifactId: project
Version: x.x
Reason: Unable to download the artifact from any repository
url.project:project:pom:x.x
from the specified remote repositories:
central (http://repo1.maven.org/)
Can anyone help me with what I'm not doing right?
Basically, I have just checked the projects out from the command line, cd-ed into the directory and ran mvn clean install - nothing else.
Any help is greatly appreciated.
the pom.xml for the project I have doesn't have this "http://repo1.maven.org/myurlhere" anywhere in it
All projects have http://repo1.maven.org/ declared as <repository> (and <pluginRepository>) by default. This repository, which is called the central repository, is inherited like others default settings from the "Super POM" (all projects inherit from the Super POM). So a POM is actually a combination of the Super POM, any parent POMs and the current POM. This combination is called the "effective POM" and can be printed using the effective-pom goal of the Maven Help plugin (useful for debugging).
And indeed, if you run:
mvn help:effective-pom
You'll see at least the following:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>
it has the absolute url where the maven repo is for the project but maven is still trying to download from the general maven repo
Maven will try to find dependencies in all repositories declared, including in the central one which is there by default as we saw. But, according to the trace you are showing, you only have one repository defined (the central repository) or maven would print something like this:
Reason: Unable to download the artifact from any repository
url.project:project:pom:x.x
from the specified remote repositories:
central (http://repo1.maven.org/),
another-repository (http://another/repository)
So, basically, maven is unable to find the url.project:project:pom:x.x because it is not available in central.
But without knowing which project you've checked out (it has maybe specific instructions) or which dependency is missing (it can maybe be found in another repository), it's impossible to help you further.
By default, Maven will always look in the official Maven repository, which is http://repo1.maven.org.
When Maven tries to build a project, it will look in your local repository (by default ~/.m2/repository but you can configure it by changing the <localRepository> value in your ~/.m2/settings.xml) to find any dependency, plugin or report defined in your pom.xml. If the adequate artifact is not found in your local repository, it will look in all external repositories configured, starting with the default one, http://repo1.maven.org.
You can configure Maven to avoid this default repository by setting a mirror in your settings.xml file:
<mirrors>
<mirror>
<id>repoMirror</id>
<name>Our mirror for Maven repository</name>
<url>http://the/server/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
This way, instead of contacting http://repo1.maven.org, Maven will contact your entreprise repository (http://the/server in this example).
If you want to add another repository, you can define a new one in your settings.xml file:
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>foo.bar</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>http://new/repository/server</url>
</repository>
</repositories>
You can see the complete settings.xml model here.
Concerning the clean process, you can ask Maven to run it offline. In this case, Maven will not try to reach any external repositories:
mvn -o clean
tl;dr
All maven POMs inherit from a base Super POM.
The snippet below is part of the Super POM for Maven 3.5.4.
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
I think what you have missed here is this:
https://maven.apache.org/settings.html#Servers
The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with the pom.xml. This type of information should exist on the build server in the settings.xml.
This is the prefered way of using custom repos. So probably what is happening is that the url of this repo is in settings.xml of the build server.
Once you get hold of the url and credentials, you can put them in your machine here: ~/.m2/settings.xml like this:
<settings ...>
.
.
.
<servers>
<server>
<id>internal-repository-group</id>
<username>YOUR-USERNAME-HERE</username>
<password>YOUR-PASSWORD-HERE</password>
</server>
</servers>
</settings>
EDIT:
You then need to refer this repository into project POM. The id internal-repository-group can be used in every project. You can setup multiple repos and credentials setting using different IDs in settings xml.
The advantage of this approach is that project can be shared without worrying about the credentials and don't have to mention the credentials in every project.
Following is a sample pom of a project using "internal-repository-group"
<repositories>
<repository>
<id>internal-repository-group</id>
<name>repo-name</name>
<url>http://project.com/yourrepourl/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
Basically, all Maven is telling you is that certain dependencies in your project are not available in the central maven repository. The default is to look in your local .m2 folder (local repository), and then any configured repositories in your POM, and then the central maven repository. Look at the repositories section of the Maven reference.
The problem is that the project that was checked in didn't configure the POM in such a way that all the dependencies could be found and the project could be built from scratch.

Categories