I have a project POM which specifies a repositories tag which points to a sandbox location.
<repositories>
<repository>
<id>mysandbox</id>
<name>Sandbox</name>
<url>http://myTestingSite.com/repositories/sandbox/</url>
</repository>
</repositories>
This works fine in Eclipse and resolves all dependencies however when i attempt to deploy i get the following exception.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-depl
oy) on project myweb-web: Deployment failed: repository element was not specified in the POM insid
e distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help
1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plug
ins:maven-deploy-plugin:2.5:deploy (default-deploy) on project myweb-web: Deployment failed: repos
itory element was not specified in the POM inside distributionManagement element or in -DaltDeployme
ntRepository=id::layout::url parameter
Wrapping this in a Distributionmanagement element doesn't make any sense because I'm using the repository for dependency resolution and not deployment.
The error says you either don't have a distributionManagement element or the element isn't correct.
So this has nothing to do with the content of <repositories>. Just create a correct distributionManagement element and it will work.
Note that the broken element might be in the parent POM. Run mvn help:effective-pom to see the complete POM as Maven sees it.
The repository that you have defined originally is only taken into consideration to download dependencies, not to upload them (as you mentioned).
What you need to add is a repository inside distribution management
<distributionManagement>
<repository>
<id>id</id>
<name>name</name>
<url>nexus_url</url>
</repository>
</distributionManagement>
And if your nexus is secured, you'll also need to define a server section for the password.
<servers>
<server>
<id>id</id>
<username>username</username>
<password>password</password>
</server>
</servers>
Related
I'm trying to share some code between two projects by loading it as a dependency via maven. For some reason, I can't get Maven to pick up the dependency.
Here's how I generated the shared JAR:
mvn install:install-file -Dfile=/Users/usr1/shared-code-1.0.0.jar -DpomFile=/Users/usr1/shared-code/pom.xml -DlocalRepositoryPath=.
This jar is held in a git repo github.com/myOrg/myRepo/repository where repository is the branch. The configuration described in the pom file for the shared code looks like this:
<groupId>com.myOrg</groupId>
<artifactId>shared-code</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
Here's how I defined the dependency and repository in my other code bases:
<dependency>
<groupId>com.myOrg</groupId>
<artifactId>shared-code</artifactId>
<version>1.0.0</version>
</dependency>
...
...
<repository>
<id>shared-code/id>
<name>Shared code for my stuff</name>
<url>http://raw.github.com/myOrg/myRepo/repository</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>\
The exact error I'm getting when I try and do a mvn clean package is:
[ERROR] Failed to execute goal on project otherCodeBase: Could not resolve dependencies for project otherCode:myProject:jar:latest: Failure to find com.myOrg:shared-code:jar:1.0.0 in http://[company's artifactory repo] was cached in the local repository, resolution will not be reattempted until the update interval of artifactory has elapsed or updates are forced -> [Help 1]
At first glance, it looks like Maven isn't even scanning the repository I defined in my other code's pom file, but when I execute mvn help:effective-pom it does appear. I should also add that I did make this repository public for the sake of getting it to work once. What gives?
I see repository tag under parent element i.e distributionManagement and repositories. What's the difference ?
<distributionManagement>
<repository>
<id>...</id>
<name>...</name>
<url>...</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>...</id>
<name>...</name>
<layout>default</layout>
<url>...</url>
</repository>
</repositories>
My understanding repository element under distributionManagement element specifies where it will deploy the artifacts at the time of deployment. It will come into picture only while mvn deploy i.e deployment time not during mvn install i.e build time. Right?
repository element under repositories element specifies from where dependencies needs to be picked up. It will come into picture only while mvn install not during mvn deploy. Right?
You have it exactly right!
From the POM reference:
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.
Repositories declared under the distributionManagement element will be used for deployment, i.e. when running mvn deploy.
The repositories element will be used for downloading dependencies of the project. The command is not necessarily mvn install but any command that requires Maven to fetch artifacts from a repository.
My pom file looks like this :
<distributionManagement>
<repository>
<id>maven-s3-release-repo</id>
<name>S3 Release Repository</name>
<!-- http://bigpetstore.s3.amazonaws.com/maven/ -->
<url>s3://bigpetstore/maven</url>
</repository>
</distributionManagement>
When I run , "mvn deploy", I get my project published to the correct repository.
However, if I run "release:prepare" followed by "release:perform", I get the following error:
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-
plugin:2.7:deploy (default-deploy) on project BigPetStorePro: Deployment failed:
repository element was not specified in the POM inside distributionManagement element or
in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
So, my question is: Why is it that "mvn deploy" is able to easily deploy my contents, however, mvn release:prepare fails to see the contents of the distributionManagement?
Clearly, the tag is present.
While using the snapshotRepository to deploy my artifact using maven with distributionManagement
<distributionManagement>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>nexus</id>
<name>nexus Snapshots</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
<layout>legacy</layout>
</snapshotRepository>
</distributionManagement>
I m stuck into the error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.6:
deploy (default-deploy) on project abc.parent: Deployment failed: repositor
y element was not specified in the POM inside distributionManagement element or
in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
The error looks that it is searching for repository element inside distributionManagement but i have defined snapshotRepository as per http://maven.apache.org/plugins/maven-deploy-plugin/usage.html and when I replace token with and url inside this with nexus releases repository url it works fine , I have read many suggestions and few at stackoverflow as well with same error but still struggling........................
The version of your project determines if it is going to use. snapshotRepository is ONLY going to be used if you version ends in "-SNAPSHOT", otherwise it will use the repository element.
If you do NOT use a -SNAPSHOT version... it will just upload to the repository you specify. It will, by defintion, be a release repo. Also this has nothing to do with Nexus but rather with how the Maven repository format works. Snapshot repositories are different from release repos and if you have a release (version does not end in -SNAPSHOT) you should upload to a release repo.
My versions:
Maven 3.0.4
Jenkins 1.499
Nexus 2.2
maven-release-plugin 3.2
jdk 1.6
AIX 6.1
settings.xml
<server>
<id>snapshots</id>
<username>deploy</username>
<password>pass123</password>
</server>
<server>
<id>releases</id>
<username>deploy</username>
<password>pass123</password>
</server>
I have a lot of builds running in Jenkins which use the maven deploy plugin and upload artifacts to the Nexus repo. Since the same user is able to deploy snapshots we can eliminate user roles/permissions issue in Nexus. (I still gave admin role to this user for testing)
Company parent POM
<distributionManagement>
<repository>
<id>releases</id>
<url>http://myserver/repositories/releases</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://myserver/repositories/snapshots</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
Project POM
<scm>
<connection>scm:svn:http://svnserver/tags/1.2.3</connection>
<developerConnection>scm:svn:http://svnserver/tags/1.2.3</developerConnection>
</scm>
I have confirmed the /target/checkout/ in the Jenkins workspace contains the latest POM. Also added <distributionManagement> inside the project POM
Now when I run maven release plugin from within Jenkins using mvn release:perform I am still getting this:
Deployment failed: repository element was not specified in the POM inside
distributionManagement element or in -DaltDeploymentRepository=id::layout
::url parameter
release:prepare shows no errors
The SVN tag gets created as expected
Then during deploy, it fails with the above error
Like I mentioned, snapshot deployment happens frequently and without error, so settings.xml, distributionManagement and Nexus permissions all seem to be in order.
I am able to access http://myserver/repositories/releases manually
I have checked with mvn help:effective-pom and mvn help:effective-settings and things seem to be in order
Any ideas ?
The error message is very explicit. There is NO distributionManagement in your POM. So you potentially are no inherting from the parent pom.
Run
mvn help:effective-pom
in the project you are trying to deploy and check. Or alternatively look at the effective POM in your IDE (Eclipse or whatever).
Then figure out the correct parent pom to use or potentially insert the distribtionManagement segment as desired.