Issue with maven deployment in snapshotRepository of Nexus - maven

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.

Related

repository tag under distributionManagement vs repositories?

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.

Maven release plugin deploy issue

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.

Maven - repositories tag preventing deployment

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>

Maven: unresolvable build extension

I've been looking at google and nothing really points to this problem. When I run "mvn clean install" it returns the following error.
[ERROR] Unresolveable build extension: Plugin
org.sonatype.flexmojos:flexmojos-maven-plugin:3.8 or one of its
dependencies could not be resolved: Failed to collect dependencies for
org.sonatype.flexmojos:flexmojos-maven-plugin:jar:3.8 ()
I'm trying to figure out how to import the maven plugin flexmojos but there are no clear directions on how to do this.
How would I import this plugin into my project?
The dependency you are looking for does exist.
To troubleshoot this problem further we'd need to see your POM and the rest of your build output.
Taking a stab in the dark:
Is this the first time you're running this build on this machine? If so, a very common "gotcha" is a corporate firewall preventing access to Maven Central. The solution in this case is setup a Maven repository manager like Nexus, or configure Maven to use a HTTP proxy.
I had a similar problem. I set up the proxy in Eclipse then I discovered I also set up the proxy in my settings.xml. I deleted the proxy from settings.xml and all worked out.
I hope my situation will help!
I solved this by adding another profile parameter from my pom.xml to my mvn command, e.g. "-Pprofile-name" pointing to a non-Maven repo definition embedded inside that profile, since Maven might be looking for repo definitions to be standing alone in a settings.xml, which isn't always the case.
I resolved this by adding a settings.xml file in the ~\.m2 directory, with the appropriate configuration pointing to our internal libraries.
If this Problem is displayed in the Eclipse Environment, this is because the m2e Connector tries to download the Plugins in to your ~\.m2\ repository
to solve this, open your Eclipse Settings: Window->Preferences and go to the ->Maven->User Settings Section.
Check if either Global Settings or User Settings is connected to the settings.xml File that your Maven uses.
Generally: Maven or your m2e connector tries to download these plugins via the plugin-repositories configured in your settings.xml it's can't find them because the repository is unknown or not reachable because you are behind a proxy or so:
08.11.18, 15:54:47 MEZ: [WARN] Failed to build parent project for com.xxx.xxx.xxx:eclipse-plugin:1.0.0-SNAPSHOT
08.11.18, 15:54:47 MEZ: [WARN] Failure to transfer org.apache.maven.plugins:maven-site-plugin/maven-metadata.xml from http://repository.sonatype.org/content/groups/sonatype-public-grid was cached in the local repository, resolution will not be reattempted until the update interval of tycho has elapsed or updates are forced. Original error: Could not transfer metadata org.apache.maven.plugins:maven-site-plugin/maven-metadata.xml from/to tycho (http://repository.sonatype.org/content/groups/sonatype-public-grid): repository.sonatype.org
go to your settings.xml file and add:
Mirrors (in this example: central repository. Do so for any other repos accordingly e.g. tycho):
<mirror>
<id>central</id>
<name>Our mirror for central repo</name>
<url>http://<your host to>/nexus/content/repositories/central/</url>
<mirrorOf>central</mirrorOf>
</mirror>
Repository:
<repository>
<id>central</id>
<url>http://<your host to>/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
</repository>
this should fix your problems:
Eclipse Specific: if Errors prevails (e.g. unknown packaging) add lifecycle mappings via Window->Preferences->Maven->Discovery->Open Catalog and add Tycho Connector
Further you can add the lifecycle-mapping plugin that handles these lifecycle mappings in the eclipse environment: eclipse m2e lifecycle mappings
Maybe you end up here because you are running nexus for a long time.
I finally found the error Summary tab in the Repositories page.
At some point Maven Central decided to require https: and the URL listed in my configuration still was using http:.
Update the URL to use https:, Save and everything worked smoothly again!

How can i use SVN as Maven Repository

I am working on project which has multiple dependencies. Most of the dependencies are available at our centralized maven repository. My project includes some JARs which only specific to my application and unavailable at our Maven repo. Due to some policy/restriction i cant deploy that jars to our maven repository.
When i install these jars in my local repository(i.e.UserHome/.m2/repository) and compile the code its working fine.
Now i want these dependencies in SVN so that we can build the application package using Continuum.(We cant refer local dependency from Continuum server.)
Just to achieve these i copied the locally installed dependency from .m2/repository and committed it in SVN. Then i declared repository in pom.xml like..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://URL/migration2/APP1/src/main/lib/</url>
<layout>default</layout>
</repository>
</repositories>
Now to use dependency from above repo i added code like...
<dependencies>
<dependency>
<groupId>repo.pu</groupId>
<artifactId>Ptestval</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
When i type mvn verify i am getting the below error..
[ERROR] Failed to execute goal on project APP1: Could not resolve dependencies f
or project fileservices.migration2:APP1:jar:1.0: Failed to collect dependencies
for [repo.pu:Ptestval:jar:1.0 (compile)]: Failed to read artifact descriptor for
repo.pu:Ptestval:jar:1.0: Could not transfer artifact repo.pu:Ptestval:pom:1.0
from/to repo.pu (https://URL/migration2/APP1/src/main/lib/): Access denied to:
https://URL/migration2/APP1/src/main/lib/repo/pu/Ptestv
al/1.0/Ptestval-1.0.pom -> [Help 1]
Could you please someone help me to resolve these issue?
EDIT: I created a repository like ..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://SVNUserName:SVNPassword#SVN_URL/BaseProj/ProjA/src/main/lib</url>
<layout>default</layout>
</repository>
</repositories>
This technique works perfectly at my Personal laptop. Maven downloads the listed dependency from repo.
But when tries to use the same in my project on company network it is not working .. It gives the same error which i was getting before using this approach.
Can anyone help me please? What would be problem? Is it a network issue?
Set up a repository manager like Nexus and don't abuse Subversion for something it was not designed for. This is unfortunately done in Google Code.
You must configure your project to use wagon-scm.
See http://maven.apache.org/wagon/wagon-providers/wagon-scm/usage.html

Resources