Reputation: 99
I'm trying to deploy maven artifacts into Artifactory repository using command : maven deploy .
I followed instructions from Maven documentation and JFrog :
https://maven.apache.org/plugins/maven-deploy-plugin/usage.html
For the moment, maven deploy:deploy-file works.
I assume credentials stored in settings.xml and corresponding repository id are correct.
But when running maven deploy I got the error :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project my-app: Failed to deploy artifacts: Could not transfer artifact com.mvn.deployment:my-app:jar:1.0-20190518.184733-1 from/to snapshots
Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
Do you have any idea why would deploy-file work and deploy is not working ?
Thanks
maven deploy:deploy-file working :
mvn deploy:deploy-file -Durl=REPO_URL \
-DrepositoryId="snapshots" \
-Dfile=PATH_TO_JAR \
-DgroupId="Project" \
-DartifactId="test-project" \
-Dversion="0.0.1-SNAPSHOT"
While mvn deploy gives an error :
mvn deploy
ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-
plugin:2.8.2:deploy (default-deploy) on project my-app: Failed to deploy
artifacts: Could not transfer artifact
com.mvn.deployment:my-app:jar:1.0-20190518.184733-1 from/to snapshots
Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
UPDATE :
I did some tests using different versions of maven and found the problem appears from version 3.5.0, the mvn deploy command works on maven 3.3.9 and I think it's related to new version of maven-wagon as in version 3.5.0 they upgraded Maven Wagon from 2.10 to 2.12.
By adding this config to my pom.xml mvn deploy works :
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.10</version>
</extension>
Upvotes: 4
Views: 10953
Reputation: 321
Interestingly, I found another reason (Maven 3.3.3 and 3.3.9): building with mvn clean install deploy
failed with this same error (Forbbiden...
) while mvn deploy
worked. I simply removed the redundant install
phase because it will execute anyway as part of deploy
phase.
PS: Yes I know, install
shouldn't be there, but that is not the point, it is just interesting how it came up with a completely unrelated error message.
Upvotes: 0
Reputation: 1105
I confirm, you had the correct answer. mvn deploy:deploy
doesn't use the credentials, even if correctly specified in the settings.xml, to upload to the repository, producing a Failed to deploy artifacts: Could not transfer artifact: Failed to transfer file xyz.jar with status code 401
error.
mvn deploy:deploy-file
works,mvn deploy:deploy
doesn't work: It doesn't use the user/password from settings.xml to upload to the repository.Your solution is correct:
<build>
<plugins>
<!-- It is a good idea to also set the maven-deploy-plugin version here -->
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.10</version>
</extension>
</extension>
</build>
This answer was based on work from Hamza.
Upvotes: 0
Reputation: 99
I did some tests using different versions of maven and found the problem appears from version 3.5.0, the mvn deploy command works on maven 3.3.9 and I think it's related to new version of maven-wagon as in version 3.5.0 they upgraded Maven Wagon from 2.10 to 2.12.
By adding this config to my pom.xml mvn deploy works :
<build>
<plugins>
<!-- It is a good idea to also set the maven-deploy-plugin version here -->
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.10</version>
</extension>
</extension>
</build>
Thanks Adrien for the maven-deploy-plugin version advice.
Upvotes: 4