How to download SNAPSHOT version from maven SNAPSHOT repository? - java

So I have a project and I do regular releases to maven without a problem. I now want to make available a SNAPSHOT version of this project. So I do 'mvn clean deploy'. Everything works as you can see below:
[INFO] Retrieving previous build number from sonatype-nexus-snapshots
Uploading: https://oss.sonatype.org/content/repositories/snapshots/me/soliveirajr/menta-regex/0.9.6-SNAPSHOT/menta-regex-0.9.6-20111010.153035-2.jar
5K uploaded (menta-regex-0.9.6-20111010.153035-2.jar)
I go to my sonatype manager and I can find the snapshot:
But now when I try to use this snapshot as a dependency on some other project in another machine I get:
<dependency>
<groupId>me.soliveirajr</groupId>
<artifactId>menta-regex</artifactId>
<version>0.9.6-SNAPSHOT</version>
</dependency>
Missing:
1) me.soliveirajr:menta-regex:jar:0.9.6-SNAPSHOT
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=me.soliveirajr -DartifactId=menta-regex -Dversion=0.9.6-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=me.soliveirajr -DartifactId=menta-regex -Dversion=0.9.6-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
So how do I force maven to download the SNAPSHOT version to my local (.m2) repository?

Just add this to your ~/.m2/settings.xml:
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>

For the sake of completeness, I would like to add that it is also possible by modifying the pom.xml of a project, simply add
<repositories>
<repository>
<id>oss.sonatype.org-snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
to your list of repositories.
In my opinion, this is a better solution than modifying ~/.m2/settings.xml. The pom.xml file will also be available for other project participants through Git and allow them to download the snapshots as well.
Source: this answer

You can enable snapshots in repository config (~/.m2/settings.xml):
<settings>
<profiles>
<profile>
<repositories>
<repository>
<snapshots> <<<<<<<<<<<
<enabled>true</enabled> << ADD THIS
</snapshots> <<<<<<<<<<<
. . .
</settings>
See maven.apache.org/settings.html#Repositories for more properties.

Related

mvn archetype:generate using internal maven repo

I wanted to create a maven project using "mvn archetype:generate ..." to create a maven project Skeleton. I looked up online and come up with this:
in settings.xml
<profile>
<id>PlatMigr</id>
<repositories>
<repository>
<id>internal repo</id>
<name>IT Maven Central</name>
<url>https://<internal maven repo></url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
From command line:
mvn archetype:generate -DarchetypeCatalog=internal -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.myproj -DartifactId=ProjName
However maven still tried to download artifacts from official central maven repo:
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
We have a firewall installed to stop internet access, that's why I struggle to use internal repo in the first place. Anyone can advise on how to setup and use internal repo to create maven projects?
Edit you settings.xml in m2_home, add mirror to you nexus and create & set to active profile without central repositories

Failed to transfer file with status code 409 maven

So I have multi module project made in java. And in one of the modules I had to add new dependency.
<dependency>
<groupId>com.donkey.great</groudId>
<artifactId>DonkeyRoll</artifactId>
<version>LATEST-SNAPSHOT</version>
</dependency>
But when importing libs I am getting error:
Failure to transfer com.donkey.great:DonkeyRoll:LATEST-SNAPSHOT
from https://artifactory.of.greatest.donkey.ever.com/artifactory/libs-release
was cached in the local repostiroy, resolution will not be reattempted until the update interval
of artifactory.of.greatest.donkey.ever.com/artifactory/libs-release has elapsed or update are forced.
Original error: Could not transfer artifact com.donkey.great:DonkeyRoll:LATEST-SNAPSHOT:
Failed to transfer file https://artifactory.of.greatest.donkey.ever.com/artifactory/libs-release/com/donkey/great/DonkeyRoll/LATEST-SNAPSHOT with status code 409
I read that mvn clean install -u could help but not in this case.
I observed that this package is already downloaded with specific version, because some of internals jars in other modules are importing it.
Anyone has idea what could go wrong? :)
Just add this to your pom.xml, and I think it should work for you.
<repositories>
<repository>
<id>oss.sonatype.org-snapshot</id>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
You can also add below to your settings.xml to make it work.
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>

How to add remote Maven repository in IntelliJ Idea?

I need to add some external dependencies to my Maven project. For example I need this library: https://packages.atlassian.com/content/repositories/atlassian-public/com/atlassian/jira/jira-rest-java-client-core/5.1.0/ I'm struggling with adding the repository in which this library is located.
I've already tried:
- adding https://packages.atlassian.com/content/repositories/atlassian-public to Settings -> Build, Execution, Deployment -> Remote Jar Repositories -> Maven Jar Repositories
- adding repository to settings.xml following this tutorial http://maven.apache.org/settings.html#Repositories, settings file here:
<?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">
<profiles>
<profile>
<id>testname</id>
<repositories>
<repository>
<id>atlassianReleases</id>
<name>Atlassian Releases</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<url>https://packages.atlassian.com/content/repositories/atlassian-public</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>testname</activeProfile>
</activeProfiles>
</settings>
updating added repository via Settings -> Build, Execution, Deployment -> Maven -> Repositories
RMB on pom.xml -> Maven -> Reimport
rebuilding the project
Of course I have correct dependencies in my pom.xml:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.1.0</version>
</dependency>
I still get error messages that used packages do not exist.
Edit:
I noticed that in my local repository I have com\atlassian\jira\jira-rest-java-client-core\5.1.0 folder but only with .pom file, _remote.repositories and .pom.sha1 file.
Edit2:
The problem was caused by my VPN settings, solved.
first you must delete com\atlassian\jira\jira-rest-java-client-core folder in .m2 directory
and again run mvn commands.
*in intellij if you changed pom.xml file ,maven plugin automatic run again
Add this to you pom.xml repositories section:
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/mvn/maven-external/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
</repository>
See documentation here https://developer.atlassian.com/server/framework/atlassian-sdk/atlassian-maven-repositories-2818705/

Not Downloading Jars from Release version

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.

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