We are trying to get the M2 Release Plugin to deploy released artifacts to our Artifactory server. The configuration in our pom.xml looks like this
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
....
<distributionManagement>
<repository>
<id>artifactory</id>
<url>http://example.com/artifactory/jenkins-release</url>
</repository>
</distributionManagement>
Using the Config File Provide Plugin we specified a global settings.xml with the proper credentials
<settings>
<servers>
<server>
<id>artifactory</id>
<username>jenkins</username>
<password>secret!</password>
</server>
</servers>
</settings>
If we now start a release build on Jenkins, Maven tells us that there it received an HTTP 401 from artifactory
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project example-maven-plugin: Failed to deploy artifacts: Could not transfer artifact com.example.maven.plugins:example-maven-plugin:jar:0.0.9 from/to artifactory (http://example.com/artifactory/jenkins-release): Failed to transfer file: http://example.com/artifactory/jenkins-release/com/example/maven/plugins/example-maven-plugin/0.0.9/example-maven-plugin-0.0.9.jar. Return code is: 401, ReasonPhrase:Unauthorized. -> [Help 1]
In the server logs we see that a user "non_authenticated_user" is trying to do a HTTP PUT request to this URL.
Is there some configuration in Maven or Jenkins we are missing? The credentials are correct and if I use the settings.xml from Jenkins on my local machine everything works as expected.
There is a bug in the Maven release plugin prior to 2.2.2 that makes it ignore the settings file being passed to Maven by the Config File Provider. The solution is to specify a newer maven release plugin in your projects pom.xml, like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
</plugin>
</plugins>
</build>
Related
I have configured a simple maven freestyle project. I was able to successfully build the project but not deploy to Nexus. I get this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy (default-deploy) on project eqs_utility: Failed to deploy artifacts: Could not find artifact com.companyName.eqs:eqs_utility:jar:1.0.1-20190529.191240-1 in nexus (https://nexus.companyRepo.com/repository/maven-snapshot/) -> [Help 1]
I have tried to change configurations to simplify the project but still nothing. Setting.xml changes.
EDITED
I added the following to my POM.xml
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>nexus</id>
<name>Company Nexus Repository</name>
<url>https://nexus.mycompany.com/repository/maven-release/</url>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>nexus</id>
<name>Company Nexus Snapshots</name>
<url>https://nexus.companyName.com/repository/maven-snapshot/</url>
</snapshotRepository>
</distributionManagement>
Then, updated my settings.xml with this
<server>
<id>nexus</id>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
<!-- Another sample, using keys to authenticate. -->
<server>
<id>nexus</id>
<username>NexusUser</username>
<password>MyLongTokenValueHere</password>
</server>
According to Apache Maven Deploy Plugin setup
You need a section:
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>MyCo Internal Repository</name>
<url>Host to Company Repository</url>
</repository>
</distributionManagement>
As you're using Nexus, you probably need a section in the pom that aligns with your nexus repositories (one for snapshots and one for release artifacts since you can't combine them in nexus):
<distributionManagement>
<repository>
<id>mavenrepository</id>
<url>http://mavenrepository.companyName.com/nexus/content/repositories/m3</url>
</repository>
<snapshotRepository>
<id>tmavenrepository</id>
<url>http://mavenrepository.companyName.com/nexus/content/repositories/m3-snapshots</url>
</snapshotRepository>
</distributionManagement>
Plus of course, in your local settings or other private location
<server>
<id>mavenrepository</id>
<username>maven</username>
<password>foobar</password>
</server>
This is described by Sonatype and cleaner by others.
Thanks to a Dropwizard Maven archetype I generated a sample Dropwizard Maven project. The pom.xml notably uses maven-source-plugin:
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
When I run "clean install" I have the following error :
Plugin org.apache.maven.plugins:maven-source-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-source-plugin:jar:2.4: Could not transfer artifact org.apache.maven.plugins:maven-source-plugin:pom:2.4 from/to central (http://repo.maven.apache.org/maven2): Connection refused: connect -> [Help 1]
The "maven-source-plugin" dependency is stored in the Nexus repository of my company. So I tried the adding of the plugin dependency between dependencies and /dependencies :
<dependencies>
...
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
but it did not correct the problem. I also tried to add the dependency at the call of the plugin :
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</plugin>
but it did not work either
Two possible situations :
Your company uses a proxy to connect to the public Maven repository. Then ask someone in your company what the IP address of the proxy is then put it in your settings.xml file
Your company has its/their own Maven repository/ies (Nexus repository for example). Then ask someone in your company what the Nexus repository is then put it in your pom.xml or in your settings.xml. See Adding maven nexus repo to my pom.xml and https://maven.apache.org/guides/mini/guide-multiple-repositories.html
It may happen, e.g. after an interrupted download, that Maven cached a broken version of the referenced package in your local repository.
Solution: Manually delete the folder of this plugin from cache (i.e. your local repository), and repeat maven install.
How to find the right folder? Folders in Maven repository follow the structure:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</dependency>
is cached in ${USER_HOME}\.m2\repository\org\apache\maven\plugins\maven-source-plugin\2.4
Update the apache-maven-3.5.0-bin\apache-maven-3.5.0\conf\settings.xml file.
Check your internet explorer proxy --> Setting --> Internet explorer -->Connection --> LAN Setting
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>user</username>
<password>****</password>
<host>proxy</host>
<port>8080</port>
</proxy>
I am using JDK 7 for maven project and I used -Dhttps.protocols=TLSv1.2 as argument in JRE. It has allowed to download all maven repository which were failing earlier.
org.apache.maven.plugins:maven-source-plugin does not exist in the repository http://repo.maven.apache.org/maven2.
You have to download it from Maven central where it exists => maven-source-plugin
Verify your pom definition or your settings.xml file.
so I am assuming that this project you are doing in your private eclipse (not company provided eclipse where you work). The same problem I resolved just as below
quick fix : got to .m2 file --> create a backup of settings.xml --> remove settings.xml --> restart your eclipse.
On my side it was coming from an error in my settings.xml file.
I had a bad tag. Just removed it, refreshed and i was good to go.
Remove the content of the folder \.m2\repository\org\apache\maven\plugins\maven-resource-plugin\2.7. The cached info turned out to be the issue.
I use intelliJ and finally I created my own settings.xml and added the following content structure to it. In my project's pom.xml, the nexus repositories were defined but for some reason it was always hitting the external apache maven repo which is blocked in my company.
<settings>
<mirrors>
<id>nexus</id>
<url>nexusURL </url>
<mirrorOf>central</mirrorOf>
<mirror>
<profiles>
<profile>
<repositories>
<repository>
</settings>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project.
Failed to deploy artifacts: Could not transfer artifactReturn code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
There was no changes made since last successful build.
I double check settings.xml(username and password).Also check in pom.xml(distribution management)
I working on this issue since last 2 days.I gone through all the forum,nothing works.please help me out.
This error message means your machine is not authenticating correctly to the Nexus machine. The credentials sent to Nexus from Maven are not correct.
When I have gotten this message, I usually have to look in my settings.xml to verify the proper credentials in this part. The username and password have to be the right ones as set in Nexus itself.
<servers>
<server>
<id>nexus-releases</id>
<username>fillin</username>
<password>fillin</password>
</server>
</servers>
I usually go the Nexus GUI and try to log in with those credentials to verify them but it is possible to configure credentials that can publish via mvn but not log into the GUI.
One possible problem is if you are using dependency-management to identify where to deploy in case of "mvn deploy" target. There is a section like this:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>releases</name>
<url>http://myNexus/more/stuff</url>
</repository>
</distributionManagement>
and the id field has to match the the id on the credentials in the settings.xml. If the ids don't match, you will get this error.
Another possible problem is that if you are using an execution for the maven-deply-plugin in your pom.xml, you might have the configuration property
<repositoryId>nexus-releases</repositoryId>
and again it doesn't match the id in the settings.xml so it fails with your error.
Similarly, if deploying using the command line option on the "mvn" command that looks like this
-DrepositoryId=nexus-releases
doesn't match the id in the settings.xml, again, it won't work.
Following our discussion in the comments section,
try to run this pom.xml
When the mvn goal should be : mvn deploy
The only two things you need is having a pom and passing the arguments:
This is the pom.xml you can use:
<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>com.hp.Maven</groupId>
<artifactId>Maven-Nexus</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<properties>
<baseNexusURL>${baseNexusURL}</baseNexusURL>
<targetRepositoryID>${repositoryId}</targetRepositoryID>
<package.final.name>${project.artifactId}</package.final.name>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>deploy-node-modules-artifact</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${file}</file>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>${packaging}</packaging>
<generatePom>true</generatePom>
<repositoryId>${targetRepositoryID}</repositoryId>
<url>${baseNexusURL}/content/repositories/${targetRepositoryID}</url>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Projects are not able to execute two life cycle phases of maven life cycle mapping:
compiler:compile
compiler: testcompile
Following are errors in eclipse:
CoreException: Could not calculate build plan: Plugin
org.apache.maven.plugins:maven-compiler-plugin:2.5.1 or one of its
dependencies could not be resolved: Failed to read artifact descriptor
for org.apache.maven.plugins:maven-compiler-plugin:jar:2.5.1:
ArtifactResolutionException: Failure to transfer
org.apache.maven.plugins:maven-compiler-plugin:pom:2.5.1 from
http://repo.maven.apache.org/maven2 was cached in the local
repository, resolution will not be reattempted until the update
interval of central has elapsed or updates are forced. Original error:
Could not transfer artifact
org.apache.maven.plugins:maven-compiler-plugin:pom:2.5.1 from/to
central (http://repo.maven.apache.org/maven2): repo.maven.apache.org
pom.xml /ex line 1 Maven Project Build
Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration:
org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile
(execution: default-compile, phase: compile) pom.xml
/ex line 1 Maven Project Build Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration:
org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testCompile
(execution: default-testCompile, phase: test-compile)
pom.xml /ex line 1 Maven Project
Build Lifecycle Mapping Problem
In eclipse goto windows->preferences->maven->user setting
point user settings textbox to setting.xml in %M2_HOME%\conf
if its not working still then you need to add plugins in the POM.xml and update project
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I have a mavenized project and when I try to do a release, I get the below error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4
.2:prepare (default-cli) on project SimpleWeb: Unable to check for local modific
ations
[ERROR] Provider message:
[ERROR] SVN status failed.
[ERROR] Command output:
[ERROR] svn: '' is not a working copy
I have the below questions:
How is the scm configuration is given in POM file
If the communication to scm should happen through https, how can we configure the certificate on the client side
The release should happen from branch or trunk
My scm configuration is as follows:
<scm>
<connection>scm:svn:https://domain.com/svn/New_FW/CI_POC/SimpleWeb/trunk</connection>
<developerConnection>scm:svn:https://domain.com/svn/New_FW/CI_POC/SimpleWeb/trunk</developerConnection>
<url>https://domain.com/svn/New_FW/CI_POC/SimpleWeb/trunk</url>
</scm>
My maven release plugin configuration is as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.3</version>
<configuration>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
<username>${scm.username}</username>
<password>${scm.password}</password>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.maven-scm-provider-svnjava</groupId>
<artifactId>maven-scm-provider-svnjava</artifactId>
<version>1.14</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
<dependencies>
<dependency>
<groupId>com.google.code.maven-scm-provider-svnjava</groupId>
<artifactId>maven-scm-provider-svnjava</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
<configuration>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
<tagBase>https://domain-inc.com/svn/New_FW/CI_POC/SimpleWeb/tags</tagBase>
<mavenExecutorId>forked-path</mavenExecutorId>
</configuration>
</plugin>
I am struck here and cant move ahead. Please help/guide me in resolving the issue. When I run the same by configuring the Maven Release Plugin in Jenkins I get a different error as: "svn: Authentication required". Why is this difference.
On Windows Jenkins slave I have same issue with multi maven project.
For fix it I added:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
...
<configuration>
<commitByProject>true</commitByProject>
...
</configuration>
...