Issue
Update based on comment:
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>https://mycompany.jfrog.io/artifactory/my-app-libs-release</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>https://mycompany.jfrog.io/artifactory/my-app-libs-snapshot/</url>
</snapshotRepository>
</distributionManagement>
Original:
My goal is to play with an end-to-end maven repository deployment and dependency import.
I am working on deploying a maven project(project name my-app) artifact to jFrog and then add the artifact as an dependency to another maven project(project name is my-second-app)
- I have setup the jFrog account
- Initialized settings.xml under folder
~/.m2/
with the jFrog credentials(username and password) and specified the URL for release and snapshots - I have added the following plugins in project my-app:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-a-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<url>https://mycompany.jfrog.io/artifactory/my-app-libs-release</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
- When I run
mvn deploy
, the projects shows 401 Unauthorized error but the artifact is deployed and can be found in jFrog packages. - I have added the dependency in project my-second-app and the dependency can be downloaded when run
mvn install
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>0.0.6-SNAPSHOT</version>
</dependency>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default) on project my-app: Failed to retrieve remote metadata com.mycompany.app:my-app:0.0.6-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.mycompany.app:my-app:0.0.6-SNAPSHOT/maven-metadata.xml from/to remote-repository (https://myurl.jfrog.io/artifactory/my-app-libs-release): authentication failed for https://mycompany.jfrog.io/artifactory/my-app-libs-release/com/mycompany/app/my-app/0.0.6-SNAPSHOT/maven-metadata.xml, status: 401 Unauthorized -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Does anyone know what I have been missing? Why I got the 401 unauthorized error? I have added the credentials in settings.xml, my understanding is it is not required to add any credential in project level.
Any help is appreciated, thanks in advance.
Solution
Maven is configured with built-in defaults that work in most cases, and the standard Maven-aware repository servers like Nexus and Artifactory will work with them with minimal configuration.
Cut out the custom configuration you have for maven-deploy-plugin
and let it use the default setup. Instead, add a distributionManagement
section with a repository
for your server, and make sure you have matching credentials in your ~/.m2/settings.xml
file.
Answered By - chrylis -cautiouslyoptimistic-