So I have a project that depends on a snapshot version of another project. The dependency is:
<dependency>
<groupId>org.oop</groupId>
<artifactId>oop</artifactId>
<version>0.9.9-SNAPSHOT</version>
</dependency>
For the oop project, I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository. But when I do a mvn clean install, the snapshot dependency above cannot be resolved and I get this:
Missing:
1) org.oop:oop:jar:0.9.9-SNAPSHOT
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-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=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Is there a way to make maven download the snapshot automatically? I must be missing something here.
EDIT1: On my settings.xml I have:
<server>
<id>sonatype-nexus-snapshots</id>
<username>XXXXXX</username>
<password>XXXXXX</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>XXXXXX</username>
<password>XXXXXX</password>
</server>
EDIT2:
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>
To update snapshots, try with the -U option
-U,--update-snapshots Forces a check for updated
releases and snapshots on remote
repositories
However, you said:
I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository.
This is just not possible, your snapshot is going somewhere else. If I do a mvn clean deploy without configuring my personal repository I get:
Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
To enable deployment, there is some configuration to be added to pom.xml, like for instance:
<distributionManagement>
<!-- Publish versioned releases here -->
<repository>
<id>myrepo</id>
<name>My releases</name>
<url>http://nexus.mycompany.com/nexus/content/repositories/releases</url>
</repository>
<!-- Publish snapshots here -->
<snapshotRepository>
<id>myrepo</id>
<name>my snapshots</name>
<url>http://nexus.mycompany.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>myrepo</id>
<name>My Public Repository</name>
<url>http://nexus.mycompany.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Maven would try to download the snapshot automatically and indeed it does (as your error indicates). By default, Maven will look for newer snapshot versions once a day, but you can change that interval in your snapshot repository config (e.g. in settings.xml):
<updatePolicy>interval:5</updatePolicy>
This will make maven check every 5 minutes (if you build that often). Alternatively, you could use the -U or --update-snapshots option, to force the check manually.
However, it can't find the dependency. Could you post your repo settings and artifact config for the snapshot dependency?
Is the org.oop:oop:jar:0.9.9-SNAPSHOT artifact in your repository?
... so the snapshot version should be somewhere in the maven central repository.
No it isn't. I tried to look it up, but couldn't find it. Afaik, there's some staging mechanism, so maybe your settings are just wrong. But normally, as the others already said, you'd go and use your own repository manager like Artifactory or Nexus.
Does that dependency exists in your repository? (in pom.xml or settings.xml)?
Looks like not. By the way, take a look at your config, just you are not using -o (offline). Also you can use -U to refresh snapshots.
You can either
use a parent project which builds all your snapshots, or
deploy your snapshots to your maven build server (nexus/archiva/..) using e.g., mvn:deploy
Let's clear up terminology a bit to make sure there is no misunderstanding.
"Maven Central" (http://search.maven.org/) is a global site where you only find releases. Central doesn't accept snapshots so deploying there should give you an error.
You probably mean your local/company wide maven proxy/cache. These can also be configured to reject snapshot versions. In case of Nexus, you can also define more complex rules. In my case, I had an issue there which gave no error during mvn deploy but I could see an error in the server's logs.
Try to follow the data: Enable debug (mvn -X) to see where Maven uploads the data. Then check the server to see whether the artifacts were really uploaded. Check the server's logs for errors.
Also note that snapshot dependencies are only refreshed once a day; so this won't work:
PC #1: mvn install -> Error missing dependency
PC #2: mvn deploy
PC #1: mvn install -> Dependency is still missing because of "update once per day" policy
Try mvn install -U to force Maven to refresh its cached metadata.
I hit the issue of snapshots not updating even when setting -U on the command line. For me the issue was my client was Maven 3 and the server was Maven 2, and in Maven 3 unique snapshots are no longer supported. We had to create a new repository with timestamped snapshots to support the 3.xx clients.
Related
I've run into a strange Maven configuration issue that I have never encountered before, and am confused as to my solution.
I have a local Nexus server that I use as a mirror for everything. Until now, I've only had the following mirror in my settings.xml file:
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>WADA Nexus</name>
<url>https://nexus.domain.org/repository/Public/</url>
</mirror>
</mirrors>
However, I recently wanted to create my own custom parent pom that I have deployed to my Nexus repo. In my project, I have pointed to my parent pom:
<parent>
<groupId>org.domain</groupId>
<artifactId>root-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
However when I now try to run my build, it fails with the following:
ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact org.domain:root-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 9, column 10
For some reason, maven is not trying to look up the parent pom in my Nexus repo.
My only workaround was to define a random repository value in my settings.xml file:
<repositories>
<repository>
<id>nexus</id>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>https://www.google.com/anythingCanGoHere</url>
<layout>default</layout>
</repository>
</repositories>
Since I've mirrored all Repos/URLs, I can set that url to any value and maven will now pick up my parent pom.
So, why do I even need to specify the repository at all? Shouldn't maven automatically try to resolve the parent pom against maven central or some other default repository?
It is not a strange configuration issue, but simply a misunderstanding from your side. What you have done is to populate <distributionManagement/> in your parent POM and added a catch-all mirror in your settings.xml with your local Nexus instance and expect it to work.
Do you actually know what you are mirroring? No! The default, hardcoded repo in Maven is Maven Central. It is a release repo which does not contain any snapshots. Therefore you see the ERROR. The bogus repo is necessary to enable Maven to request snapshots from your Nexus instance otherwise it will only request releases. Nexus in turn has a repo group with Central and your hosted release and snapshots repos.
As long as you don't define any snapshot repos in your POMs (which you shouldn't) Maven will never be able to download any snapshots.
I am trying add this dependency in my pom.xml, but maven is not able to resolve the dependency for the same.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
I was working on my other computer some weeks ago. I switched my laptop, and trying to setup this project, but it's not working anymore.
Error:
Missing artifact org.springframework:spring-test:jar:4.3.4.RELEASE
I see this this is available in the maven central.
http://search.maven.org/#artifactdetails%7Corg.springframework%7Cspring-test%7C4.3.4.RELEASE%7Cjar
Does anybody have any idea why is it happening?
Thank you #Reek for the comment.
I added spring repository url in my pom.xml and it started working.
<repository>
<id>repository.spring.release</id>
<name>Spring GA Repository</name>
<url>http://repo.spring.io/release</url>
</repository>
You do not need to add spring specific repository to use those artifacts.
Maven works as follows:
Firstly Maven tries to find artifact in the local repository.
Otherwise Maven tries to download artifacts from http://repo1.maven.org/maven2/ by default.
If you wanna build your project on another computer for the first time than there is no local repository at the moment. There are two possible reasons for Error on the second stage:
Maven central repository is unavailable from another computer: check this URL.
Mirror of Maven central is misconfigured in settings.xml like this:
<mirrors>
<mirror>
<id>central-proxy</id>
<name>Proxy of Maven Central</name>
<url>http://some/invalid/url/here</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
Detailed logs are required.
I am newbie using maven m2e plugin in my eclipse and JFrog Artifactory.
As given in the instructions I downloaded JFrog Artifactory war and deployed it using Tomcat 8 Windows installer service. I am using windows 8.1 64 bit OS.
Once the artifactory been deployed through tomcat i added some jars required for my project through Deploy option in artifactory into ext-release-local and maven-clean, other such jars to plugins-relase-local.
Then i generated settings.xml file and copied it to .m2 file. My settings.xml file consists of
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://localhost:8082/artifactory/libs-release</url>
</repository>
<repository>
<snapshots/>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://localhost:8082/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://localhost:8082/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots/>
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://localhost:8082/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
And then when I tried to clean install -X -e the project I am getting the following exceptions.
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1: Failure to find org.apache.maven.plugins:maven-clean-plugin:pom:2.4.1 in http://localhost:8082/artifactory/plugins-release was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
How to integrate Artifactory with Maven.
The primary goal is only for the very first time the jars and other dependencies should be fetched from central repository, all other times the jars should be fetched from local repos.
how to deploy jars in bundle. Example : Deploying all jars of spring 4.X in a single deployment process.
Any guide or proper documentation or rules of thumb explaining proper way of maintaining repositories etc.,
How to change admin username and password of Artifactory. creating multiple users in Artifactory with user defined roles. etc.,
More very simple best practices/ tutorial explaining how to configure and use Artifactory with Maven
One more issue with the Artifactory web UI is its often freezing and when i check it out with the tomcat service in task manager the tomcat freezes with 'stopping..'. And ended up in connection reset error in browser. I cant stop the service immediately through tomcat configurer. The tomcat is taking too long time to stop and restart. Any clues to properly use tomcat deploy?
Thanks
Your Artifactory should proxy external repositories with the most common artifacts and plugins. E.g. the maven-clean-plugin should be resolved without any problems. If Artifactory is behind proxy, you should configure it in the Admin screen as described in the User Guide.
I would generally suggest going though it, it should answer all the mentioned questions.
Regarding freezes - if you deployed the war into existing Tomcat installation without configuring its JVM paramteres, the freezes you see are full GC cycles - you are running out of memory. That brings us to the User Guide again.
We have numerous Java projects, which are CI built with Jenkins. These are deployed to our own Nexus server just fine.
The problem is, we need to provide these libraries to a third party, but without the source code.
So for each project, in Nexus we have:
Releases repository for our devs (includes deployed source code)
Snapshots repositories for our devs (includes deployed source code)
Third party release repository (only JAR + POM)
(and would be good to have): Third party snapshot repository (only JAR + POM) for third party nightly builds
The question is: how is this usually handled in Jenkins/Nexus world? I'd prefer to have one single Job in Jenkins which handles the CI build and the release (artefact deployment) process "automatically".
Currently I'm using multiple <distributionManagement> profiles in our "main root pom.xml" (included by all projects):
[...]
<profiles>
<profile>
<id>default</id>
<distributionManagement>
<repository>
<id>releases</id>
<name>Release</name>
<url>http://path/to/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshot</name>
<url>http://path/to/nexus/content/repositories/snapshots/</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
</profile>
<profile>
<id>third-party</id>
<distributionManagement>
<repository>
<id>releases</id>
<name>Release</name>
<url>http://path/to/nexus/content/repositories/third-party/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshot</name>
<url>http://path/to/nexus/content/repositories/third-party-snapshots/</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
From the Maven docs, it seems to be no way of using multiple repositories during the same build lifecycle, not to mention the fact that we need/don't need the source based on the target repo.
I can do a trick with creating a Job in Jenkins, with the Maven "Goals and options": clean deploy -P third-party and then adding the Post-build action - "Deploy artifacts to Maven repository" with the "default" data - but in this case, only SNAPSHOTs are going to both repo and artefacts released via Jenkins Maven Release Plug-in are going into one repository only.
Any practical ideas how can I do this without overcomplicating our CI job hierarchy?
Thanks in advance!
You can just handle this all in Nexus. Create a repository target that contains a pattern like the one used in the preconfigured example "All but sources (Maven 2)" and narrow that target down even further with another pattern that restricts the groupid, artifactid and maybe even version.
Then create a privilege that uses that repository target and assign it to the user or role you want to have the respective access.
No need to do multiple deployments or some such..
See http://books.sonatype.com/nexus-book/reference/repository-targets.html
You can use Maven Wagon Plugin and upload a single jar to a remote location on deploy phase.
Is it possible to distribute my application with its POM only ?
I have deployed my application in a remote repository and I think it would be nice if I can distribute only its POM, instead of asking the users to download the complete source first and use the POM to build the application afterwards.
The idea is that users would be able to install the application using the POM and a single Maven command.
I tried adding to the POM a downloadURL in a distributionManagement section without success. Here my experiment:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>aGroupId</groupId>
<artifactId>anArtifactId</artifactId>
<version>0.0.1</version>
<distributionManagement>
<downloadUrl>anURL</downloadUrl>
</distributionManagement>
<repositories>
<repository>
<id>someId</id>
<url>anURL</url>
</repository>
</repositories>
</project>
Thanks in advance for any feedback
If you're distributing source, then you should look at the bootstrap POM method: http://maven.apache.org/scm/maven-scm-plugin/examples/bootstrapping-with-pom.html
where the 'scm' element is key. The user has only to run scm:bootstrap to then receive the project source tree from which to build the project.
-tim
You can use the dependency:get mojo to download an artifact to a specified location:
mvn dependency:get -Dartifact=<groupid>:<artifactid>:<version> /
-Ddest=path/to/destination.jar