Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy - Cannot deploy artifacts when Maven is in offline mode - maven

I run project deploy in Maven project and get the problem as below:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project iris: Cannot deploy artifacts when Maven is in offline mode -> [Help 1]
Could you help me figure out this problem?

Maven is configured in offline mode, that means Maven will not try to connect to any remote repository. Therefore, the maven-deploy-plugin cannot upload your jar.
Offline mode can be configured in two different ways :
launching Maven with the -o flag. Maven is offline only for this execution.
setting the offline attribute to true in the settings.xml file. Maven is offline for all executions.
One of those two options must be enabled in your configuration and you must remove it for maven-deploy-plugin to work.

Related

Maven - jenkins pipeline not using pom

I have a problem running a maven deploy through Jenkins. When run locally, the correct URL is contacted, but via Jenkins(in the middle of a pipeline), it does not. It also states that it is using a different plugin to do so. How do I get Jenkins to contact MY_URL like my command line does?
(I've cleaned up the output a bit)
Running the following through the command line gives me:
mvn clean deploy -DaltDeploymentRepository=nexus::default::https://MY_URL/ -DskipTests -P nexus -X -s ./settings.xml
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project MY_PROJECT: Failed to deploy artifacts: Could not transfer artifact from/to nexus (https://MY_URL): Failed to transfer file 20200217.092316-15.jar with status code 401 -> [Help 1]
This is what I want (I'm waiting on credentials - but it is hitting the correct URL)
Running via Jenkins gives me:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1: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 -> [Help 1]
I have done a "diff" on the pom files in use by jenkins and locally and they are identical; likewise with the settings.xml I suspect this is a plugin problem but do not know where to go with it.
Items I have tried:
mvn clean beforehand
reinstalling mvn
echoing the settings.xml and pom.xml into the jenkins output
Specifying altDeploymentRepository in the settings.xml and/or
commandline
Specifying altDeploymentRepository using the -Dproperties= flag
Combinations of altDeploymentRepository, altDeploymentDirectory,
altSnapshotDeploymentRepository
Endless research
Hopeful reruns
Banging head on desk
Your Jenkins runs the org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy goal.
It is either specified in the POM or given on command line. So first of all, check whether the nexus-staging-maven-plugin is configured in your POM or in one of the parent POMs. If so, check if it run conditionally or is part of a profile.
Secondly, look at the command line call in Jenkins and see if it is exactly the same as the one you ran locally.
The third possibility is that you run a Jenkins plugin from Sonatype that implicitly tries to deploy artifacts. So watch out for Sonatype specific Jenkins plugins.
One of the three strategies should lead to the source of the problem.

Could not find artifact and could not resolve dependencies

I'm working in a maven project which contains many dependencies, i have a dependency from a centralized remote NEXUS repository ,so i should have a specific configuration in my setting.xml..
so When i launch clean install from the maven tab in intellij it displays errors:
ERROR] Failed to execute goal on project calender: Could not resolve
dependencies for project com.orange:calender:war:1.0-SNAPSHOT: Could
not find artifact com.francetelecom.clara.component:security:jar:3.0.0
in central (https://repo.maven.apache.org/maven2) -> [Help 1]
but when i switch to the Terminal tab in intellij the build succeed without errors and when i try to deploy the war within Tomcat it won't.
Tomcat log:
java.lang.NoSuchMethodError:
org.apache.commons.collections.ArrayStack: method (I)V not found
at org.apache.commons.digester.Digester.(Digester.java:150) at
com.francetelecom.clara.security.config.SecurityConfig.parse(SecurityConfig.java:95)
at
com.francetelecom.clara.security.SecurityManager.initialize(SecurityManager.java:114)
at
com.francetelecom.clara.security.SecurityManager.(SecurityManager.java:99)
at
com.francetelecom.clara.security.SecurityManager.getContextInstance(SecurityManager.java:371)
When running maven from maven tab in IntelliJ, you use the settings you find from Alt/Ctrl S -> Build, Execution, Deployment > Build Tools > Maven
When running from terminal in IntelliJ it will use first mvn you find on PATH and use configuration from what you get there. "mvn -version" from terminal will show you your Maven Home when running mvn from terminal

How can I resolve a 401 failure when deploying a Maven artifact from Jenkins to Artifactory using the Artifactory Plugin and the Credentials Plugin?

I use Jenkins to build a Maven project.
I have the Jenkins Credentials Plugin and the Jenkins Artifactory Plugin.
I have added my Artifactory credentials in the Credentials config.
I have configured the Artifactory plugin to use the Credentials and have set up the server URL. Test Connection works and reports back that it has found the server.
My project's POM specifies the correct Artifactory paths for the repository and the snapshotsRepository in the distributionManagement section.
My Jenkins project build is configured to do a mvn deploy.
In my local build, from my development machine, I can deploy to the Artifactory server (I have configured the credentials in my settings.xml.
However, in my Jenkins job, I want to use the Artifactory plugin and the Credentials int he Credentials plugin. When I build, I get the following
[DEBUG] Using connector WagonRepositoryConnector with priority 0 for http://xxxxx/artifactory/libs-release-local
Uploading: http://xxxxx/artifactory/libs-release-local/xxx/3.01/xxx-3.01.war
Uploading: http://xxxxx/artifactory/libs-release-local/xxx/3.01/xxx-3.01.pom
Notifying upstream projects of job completion
Join notifier requires a CauseAction
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
and the following stack trace
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project querynator:
Failed to deploy artifacts: Could not transfer artifact xxx:war:3.01 from/to dwCentral (http://xxxxx/artifactory/libs-release-local):
Failed to transfer file: http://xxxxx/artifactory/libs-release-local/xxx/3.01/xxx-3.01.war.
Return code is: 401, ReasonPhrase: .
This indicates to me the issue is with credentials, particularly since I can deploy from my dev box (using credentials in settings.xml), but not from Jenkins.
I have tried deploying a new version. I have tried deploying snapshots. This is not a version issue.
How can I I resolve this? How can I troubleshoot this further?
When using the Artifactory plugin in Jenkins, you should not use mvn deploy in the main build task. That uses the Maven Deploy Plugin, and hence will try to use credentials stored in the settings.xml file.
Instead, use mvn install as the main build task, and set up a new post-build task to Deploy Artifact to Repository.
This allows you to define the server, repository locations, and credentials to use.
Assuming you have already configured the credentials properly. If you have already deployed version lets say x.y.z to the artifactory once. Executing the command
mvn deploy
again for the same version would also result in the
Return code is: 401, ReasonPhrase: Unauthorized.
You can try updating the version to x.y.a which has never been deployed, the job should just run fine.
More from the documentation at Maven Lifecycle Basics
deploy - done in the build environment, copies the final package to
the remote repository for sharing with other developers and projects.
and assuming that you understand What exactly is a Maven Snapshot and why do we need it? and agree upon the fact that once a project is shared across things shouldn't be changing on the fly for consumers, the deploy phase is not permitted for the same version more than once.

Can't deploy Maven jars to S3 from Intellij

I'm trying to deploy a Maven jar to S3 from within IntelliJ (meaning, using the Maven Projects panel). This fails constantly, saying:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MyProject: Failed to deploy artifacts: Could not transfer artifact Project:MyProject:jar:1.0.0 from/to s3-spark.release (s3://MyS3): Unable to load AWS credentials from any provider in the chain -> [Help 1]
But, when I try to do the same from within the terminal using mvn deploy, everything works great. Any ideas what am I missing? (Using Maven 3.3.9, IntelliJ Comumnity 2016.1)

Configuring Maven, jenkins with Sonar

I have installed Jenkins and Sonar, both work fine. I am able to build a maven android project using Jenkins. No i want to run Sonar on the android project. I have installed the Sonar plugin in Jenkins. Configured the sonar module in the configure system module and added a post build task for sonar to run
[ERROR] Plugin org.codehaus.mojo:sonar-maven-plugin:sonar or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.mojo:sonar-maven-plugin:jar:sonar: Could not find artifact org.codehaus.mojo:sonar-maven-plugin:pom:sonar in nbs-repo (http://10.10.2.89:8081/nexus/content/groups/public/) -> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin org.codehaus.mojo:sonar-maven-plugin:sonar or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.mojo:sonar-maven-plugin:jar:sonar
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:129)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor(DefaultMavenPluginManager.java:142)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getMojoDescriptor(DefaultMavenPluginManager.java:261)
at org.apache.maven.plugin.DefaultBuildPluginManager.getMojoDescriptor(DefaultBuildPluginManager.java:185)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor(MojoDescriptorCreator.java:235)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:106)
at
My nexus installation works fine ? What am i doing wrong. My maven pom.xml does not contain any sonar plugin. What am i doing wrong?
Kind Regards
From the error message its clear that mvn is trying to download the sonar-maven-plugin from your local Nexus repository which does not seem to have it.
Try mvn -U in the build in case you already have the plugin.This overrides the negative cache. Another thing is <updatepolicy> in your settings.xml
If you don't have the plugin and neither does your Nexus connect to the internet, you have to manually download and upload in Nexus of course. Please remember to match the version of the plugin with the SONAR installation. Also there would be a few (7-10) transitive dependencies with the plugin which you will need. I suggest using mvn -X or mvn -e to see a verbose output during your testing.

Resources