nexus-staging-maven-plugin 401 Unauthorized - maven

I am getting a 401 Unauthorized exception from deploying the maven. Here is the relevant section of the pom file.
<!-- pom.xml -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>[version]</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<nexusUrl>[your-nexus-base-url]</nexusUrl>
<serverId>[your-nexus-base-id]</serverId>
<skipStaging>true</skipStaging>
</configuration>
</plugin>
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>[your-nexus-base-url]/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>[your-nexus-base-url]/content/repositories/releases/</url>
</repository>
</distributionManagement>
<!-- settings.xml -->
<servers>
<server>
<id>[your-nexus-base-id]</id>
<username>[username]</username>
<password>[encrypted-password]</password>
</server>
</servers>

You must have an ID in your settings.xml file to match the ID under the distribution management. NOT ONLY the ID in the nexus plugin.
<!-- pom.xml -->
<distributionManagement>
<snapshotRepository>
<id>[your-nexus-base-id]</id>
<url>[your-nexus-base-url]/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>[your-nexus-base-id]</id>
<url>[your-nexus-base-url]/content/repositories/releases/</url>
</repository>
</distributionManagement>
<!-- settings.xml -->
<servers>
<server>
<id>[your-nexus-base-id]</id>
<username>[username]</username>
<password>[encrypted-password]</password>
</server>
</servers>

Related

Maven deploy:file step: automatically deploy to snapshot or to release repository

I have the following sections in my pom.xml
<repositories>
<repository>
<id>maven-booking-snapshots</id>
<url>https://artifactory.booking.com/maven-booking-snapshots</url>
</repository>
<repository>
<id>maven-booking-releases</id>
<url>https://artifactory.booking.com/maven-booking-releases</url>
</repository>
<distributionManagement>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Snapshot Repository</name>
<url>https://artifactory.com/maven-snapshots</url>
</snapshotRepository>
<repository>
<id>maven-releases</id>
<name>Release Repository</name>
<url>https://artifactory.com/maven-releases</url>
</repository>
</distributionManagement>
and
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>com.shaded.google</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>hidden.io.netty</shadedPattern>
</relocation>
</relocations>
<shadedArtifactAttached>false</shadedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-nodeps</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/original-${project.artifactId}-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<classifier>nodeps</classifier>
<url>${project.distributionManagement.repository.url}</url>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>
When I run the mvn deploy:file the file is going to be uploaded always in the release repository and (I think) the problem is that the <repository> tag of the plugin points to project.distributionManagement.repository.url. At the same time, I cannot make it point to the project.distributionManagement.snapshotRepository because I would like that the deployment destination depends on the version of the pom. How can I achieve such flexibility in the run of the deploy plugin?

How can you use a dependency from the plugin's dependency scope in the maven-antrun-plugin?

We have a profile that uses maven-antrun-plugin to run a downloaded JAR.
Exhibit A: (this works)
We can reference the downloaded JAR using the property ${maven.dependency.com.foobar.target-jar.jar.path} (Can I use the path to a Maven dependency as a property?). But in this solution, the custom dependency and repository information isn't limited to just the scope of the profile.
<project>
...
<repositories>
<repository>
<id>thirdparty</id>
<name>Third Party</name>
<url>
[URL for the repository that holds the target JAR]
</url>
<layout>default</layout>
</repository>
</repositories>
...
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>target-jar</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
...
<profiles>
<profile>
<id>runJARprofile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<inherited>false</inherited>
<executions>
<execution>
<id>run-jar</id>
<phase>package</phase>
<configuration>
<target name="runJar" fork="true">
<java jar="${maven.dependency.com.foobar.target-jar.jar.path}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>
Exhibit B: (haven't gotten it working)
Here, we moved the dependency and repository information into the profile. Maven downloads the artifact successfully, but we no longer know how to reference it by property.
<project>
...
<profiles>
<profile>
<pluginRepositories>
<repository>
<id>thirdparty</id>
<name>Third Party</name>
<url>
[URL for the repository that holds the target JAR]
</url>
<layout>default</layout>
</repository>
</pluginRepositories>
...
<id>runJARprofile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<inherited>false</inherited>
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>target-jar</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>run-jar</id>
<phase>package</phase>
<configuration>
<target name="runJar" fork="true">
<java jar="${?????}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>
I crated a POM similar to your Exhibit B here and got the following message during a mvn package -P runJARprofile:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run
(run-jar) on project so-36848518: An Ant BuildException has occured:
Cannot execute a jar in non-forked mode. Please set fork='true'.
[ERROR] around Ant part ...<java jar="${my:test:jar}"/>...
I changed the respective line to:
<java jar="${my:test:jar} fork="true"/>
and:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Where to specify the repository element for Artifactory release?

I am trying to release a project in the Artifactory repository. It’s a project which is a dependency of my main project, so I would like to put the pom, the .jar and the sources.jar in the artifactory repository.
The settings.xml file is stored in the maven directory :
D:\...\...\maven\apache-maven-3.3.1\conf
I have already tagged the version using following maven command :
mvn clean release:prepare
Then, if I try :
mvn clean release:perform –Partifactory
, I get the error :
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project ........ : Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
What should I do to use the artifactory profile ? Is it possible without changing the pom ?
I have tried without success to copy the settings.xml in my local maven repository.
If I have to change the pom, can I first come back before the state obtained after the mvn release:prepare command ? In the following link, I didn’t understand if I have to do something manually or not (remove tag from the SCM) :
http://maven.apache.org/maven-release/maven-release-plugin/examples/rollback-release.html
The settings.xml file :
<?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">
<localRepository>D:\...\...\maven\repository</localRepository>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://x/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://x/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://x/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://x/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
The pom :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>....</groupId>
<artifactId>my-parent</artifactId>
<version>1.0.6</version>
<relativePath />
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>....</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<version>1.9.6-SNAPSHOT</version>
<name>myproject</name>
<url>${wiki.url}</url>
<scm> <developerConnection>scm:svn:http://x/svn/main/y/Development/Components/trunk/myproject</developerConnection>
<url>http://x/svn/main/y/Development/Components/trunk/myproject</url>
</scm>
<ciManagement>
<system>${ciManagement.system}</system>
<url>${ciManagement.url}/${project.artifactId}</url>
</ciManagement>
<properties>
</properties>
<dependencies>
<! - - my dependencies - - >
</dependencies>
<build>
<plugins>
<plugin>
<inherited>false</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration> <tagBase>http://x/svn/main/y/Development/Components/tags</tagBase>
</configuration>
</plugin>
</plugins>
</build>
</project>
The parent pom :
<!-- language: lang-xml -->
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>....</groupId>
<artifactId>my-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.6</version>
<name>my-parent</name>
<url>${wiki.url}</url>
<scm>
<developerConnection>scm:svn:http://x/svn/main/y/Development/Components/tags/my-parent-1.0.6</developerConnection>
<url>http://x/svn/main/y/Development/Components/tags/my-parent-1.0.6</url>
</scm>
<ciManagement>
<system>${ciManagement.system}</system>
<url>${ciManagement.url}/${project.artifactId}</url>
</ciManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
</plugins>
</build>
</project>
Two things. You should declare a <distributionManagement> section in your POM:
<project>
...
<distributionManagement>
<repository>
<id>my-artifactory</id>
<name>Artifactory Release Repo</name>
<url>http://x/artifactory/libs-release</url>
</repository>
<snapshotRepository>
<id>my-artifactory</id>
<name>Artifactory Release Repo</name>
<url>http://x/artifactory/libs-snapshot</url>
</snapshotRepository>
</distributionManagement>
</project>
The <id> tags must match an entry in your settings.xml for the credentials to match:
<settings>
...
<servers>
<server>
<id>my-artifactory</id>
<username>bob</username>
<password>secret</password>
</server>
</servers>
</settings>
Now, that being said, since mvn release:prepare has already tagged the release in your VCS, you don't need to cut a new release, but I would advise you to add the <distributionManagement> section to the POM. One way to deploy the artifacts is to simply get the tag from the VCS and do an mvn deploy, like so:
svn co <the url to your tag>
mvn -DaltDeploymentRepository=my-artifactory::default::http://x/artifactory/libs-release deploy

Maven release process consistently failing : svn: E175013: Access to '/svn/tester/!svn/bc/170' forbidden

I have been banging my head for quite a while now and I have actually learnt lots of this issues on stackoverflow an pretty sure I covered some of the common mistakes(besides,I have done several releases with bitbucket and github) that were starring at me. But still I have not been able to release anything. I feel like it's time to shout for a little help :)
I use a self hosted subversion managed by usvn and a sonatype private nexus repository. I have a multi module maven project arrange in a parent and sub module model.
Below is the snippet of the parent pom that is relevant
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<excludes>
<exclude>**/*ITest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding} </encoding>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding} </encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<preparationGoals>clean verify -DenableIT=true</preparationGoals>
<tagBase>https://repo.mysvnserver.com/svn/tester/tags</tagBase>
</configuration>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<distributionManagement>
<repository>
<id>dal</id>
<url>http://nexus.mynexusserver.com/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:svn:https://username#repo.mysvnserver.com/svn/tester</connection>
<developerConnection>scm:svn:https://username#repo.mysvnserver.com/svn/tester</developerConnection>
<url>https://repo.mysvnserver.com/usvn/project/tester/browser</url>
<tag>tester</tag>
</scm>
Below is my settings.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<settings >
<localRepository>/home/joseph/.m2/repository</localRepository>
<servers>
<server>
<username>username</username>
<password>password</password>
<id>nexus</id>
</server>
<server>
<username>username</username>
<password>password</password>
<id>dal</id>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://nexus.mynexusserver.com/nexus/content/repositories/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>dal</id>
<url>http://nexus.mynexusserver.com/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Since it would probably too much to put the output here , please find it on paste.ee .
I am more convince this is either configuration issue on subversion side because things looks fairly ok to me. Can anyone point out something I am missing?
Thanks
The SCM part of your POM looks not related to an actual SVN branch (or the trunk) of a project. For the SCM-linked part of the release plugin to work, I guess an SCM configuration closer to what is described in the SCM plugin should be made. A project POM SCM information should describe where to get the source code related to that exact project version, not the root project location.
I guess that without this, SVN can trigger unexpected authorization issues as you are in fact trying to access an URL where you might not have set permissions.

Maven: Changing remote directory structure

I have just started to learn maven a few weeks ago. Currently trying to achieve the structure in my mind. Everything up to know is perfect but, i am having an issue about deploying.
The issue is:
when i perform mvn release:perform artifacts are being deployed to my ftp server in ftp://centos-release/maven/linuxapp/releases/com/gmail/baturman/linuxapp/linuxapp/0.0.5/ path.
and when i perform mvn deploy current snapshot is being deployed to ftp server in ftp://centos-gitlab/maven/linuxapp/snapshots/com/gmail/baturman/linuxapp/linuxapp/0.0.6-SNAPSHOT/
everything is cool but, this is not the structure that i want. What i want to have this directory structure:
For release: ftp://centos-release/maven/linuxapp/releases/0.0.5/
For snapshots: ftp://centos-release/maven/linuxapp/snapshots/0.0.6-SNAPSHOT/
Could you please advise?
Here is my pom file.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.baturman.linuxapp</groupId>
<artifactId>linuxapp</artifactId>
<version>0.0.5-SNAPSHOT</version>
<description>Linux App - Powered by git and maven :)</description>
<name>Linux App</name>
<!-- PROPERTIES -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- DEPENDENCIES -->
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<!-- RELEASE INFORMATION -->
<scm>
<connection>scm:git:gitlab#centos-gitlab:maven/linuxapp.git</connection>
<developerConnection>scm:git:gitlab#centos-gitlab:maven/linuxapp.git</developerConnection>
<url>http://centos-gitlab/maven/linuxapp</url>
<tag>v0.0.3</tag>
</scm>
<distributionManagement>
<repository>
<id>release-server</id>
<name>Release Repository</name>
<url>ftp://centos-gitlab/maven/${project.artifactId}/releases</url>
</repository>
<snapshotRepository>
<id>release-server</id>
<name>Snapshot Repository</name>
<url>ftp://centos-gitlab/maven/${project.artifactId}/snapshots</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
<!-- BUILD -->
<build>
<finalName>${project.artifactId}</finalName>
<!-- EXTENSIONS -->
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>2.4</version>
</extension>
</extensions>
<!-- RESOURCES -->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/conf</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
</resource>
</resources>
<!-- PLUGINS -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<useJvmChmod>true</useJvmChmod>
</configuration>
<executions>
<execution>
<id>release-server</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
First i would suggest to start using a repository manager like Nexus, Artifactory or Archiva which is a better solution than an ftp server. Apart from that you have to change your definitions:
<distributionManagement>
<repository>
<id>release-server</id>
<name>Release Repository</name>
<url>ftp://centos-gitlab/maven/releases/</url>
</repository>
<snapshotRepository>
<id>release-server</id>
<name>Snapshot Repository</name>
<url>ftp://centos-gitlab/maven/snapshots/</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>

Resources