SonarQube Jenkins Plugin won't authenticate to Artifactory - maven

SonarQube 5.1 running on Ubuntu 12.04.4 LTS
Jenkins ver. 1.616 running on Ubuntu 12.04.4 LTS
SonarQube Plugin 2.2.1
Artifactory Pro Power Pack 3.8.0 (rev. 30190) running on Ubuntu 12.04.5 LTS
sbt 0.13.8
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk1.8.0_45/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-23-generic", arch: "amd64", family: "unix"
Attempting to use the SonarQube Jenkins Plugin in a Jenkins Build, the plugin seems to try to rebuild the entire build and re-resolve all the dependencies out of Artifactory. Problem is, unlike the rest of the build, when the SonarQube plugin requests artifacts from Artifactory, it does so as a non-authenticated-user, and Artifactory refuses the request.
I've tried everything from copying the <servers/>, <profiles/>, and <activeProfiles/> from the jenkins user's settings.xml file into /etc/maven.settings.xml and explicitly telling the plugin to use the former as user settings and the latter as system settings - in short, anything and everything I could find documented to medieval brute force the plugin to use the jenkins user's credentials , but still it just keeps connecting as a non-authenticated user and having its requests refused.
Example from Jenkins Log (sensitive information obfuscated):
INFO: No credentials available for BASIC 'Artifactory Realm'#libs.<organization>;:443
[WARNING] Could not transfer metadata <GAV>/maven-metadata.xml from/to ArtifactorySnapshotsRepo (<Artifactory URL>/artifactory/libs-snapshot/): Not authorized.
[WARNING] The POM for org.codehaus.jackson:jackson-core-asl:jar:1.8 is missing, no dependency information available
[WARNING] The POM for org.codehaus.jackson:jackson-mapper-asl:jar:1.8 is missing, no dependency information available
[WARNING] Failure to transfer <GAV>/maven-metadata.xml from <Artifactory URL>/artifactory/libs-snapshot/ was cached in the local repository, resolution will not be reattempted until the update interval of ArtifactorySnapshotsRepo has elapsed or updates are forced. Original error: Could not transfer metadata <GAV>/maven-metadata.xml from/to ArtifactorySnapshotsRepo (<Artifactory URL>/artifactory/libs-snapshot/): Not authorized.
And in Artifactory's request.log we get (again with sensitive information obfuscated):
20150916190344|5181|REQUEST|<Jenkins IP>;|non_authenticated_user|GET|/libs-snapshot//<GAV>/maven-metadata.xml|HTTP/1.0|401|0
The maven command launched by the SonarQube Plugin was as follows (lines broken for clarity, sensitive information obfuscated):
mvn
-f /var/lib/jenkins/workspace/NE-BUILD-1/pom.xml
-s /var/lib/jenkins/.m2/settings.xml
-gs /etc/maven/settings.xml
-e
-B org.codehaus.mojo:sonar-maven-plugin:2.6:sonar
-Dsonar.jdbc.url=jdbc:postgresql://<server>:<port>/sonar
******** ********
-Dsonar.host.url=http://<server>:<port>/
-Dsonar.branch=sbt-publish-deb ******** ********
How can I make this process authenticate to Artifactory properly?

Related

Error when creating Maven project from archetype: 501 HTTPS Required

I run mvn archetype:generate and get this error:
Error reading archetype catalog http://repo.maven.apache.org/maven2
org.apache.maven.wagon.TransferFailedException: Transfer failed for http://repo.maven.apache.org/maven2 501 HTTPS Required
I'm using Maven 3.6.3.
I cannot put a different repository URL into the POM file, because when I'm creating a project from an archetype, no POM file exists yet.
I have no settings.xml file in ~/.m2.
Is there something wrong with my Maven installation?
The output of mvn --version is:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 11.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
/usr/local/Cellar/maven/3.6.3_1/libexec/conf/settings.xml does not contain the URL that the error message is complaining about.
Short answer: override the default http catalog url with an https one, by appending:
-DarchetypeCatalog=https://repo.maven.apache.org/maven2/archetype-catalog.xml
to the mvn archetype:generate command
Background:
When using the mvn -X -e archetype:generate command, Maven 3.6.3 seems to use version 2.4 of the maven-archetype-plugin:
[DEBUG] Resolved plugin version for org.apache.maven.plugins:maven-archetype-plugin to 2.4 from repository central (https://repo.maven.apache.org/maven2, default, releases)
The plugin uses the remote catalog: http://repo.maven.apache.org/maven2/archetype-catalog.xml:
[DEBUG] Searching for remote catalog: http://repo.maven.apache.org/maven2/archetype-catalog.xml
[DEBUG] Searching for remote catalog: http://repo.maven.apache.org/maven2
[WARNING] Error reading archetype catalog http://repo.maven.apache.org/maven2
org.apache.maven.wagon.TransferFailedException: Transfer failed for http://repo.maven.apache.org/maven2 501 HTTPS Required
As of 15/1/2020, maven central requires an HTTPS url: Central 501 HTTPS Required
According to this JIRA, the issue should be fixed in version 3.0.0 of the plugin.

MVN release fails with "Repository does not allow updating assets: releases" when it should not

We have a multi module project for which we want to do a release using the following command
mvn release:prepare release:perform -B -e -X
which fails with
07:54:12 [INFO] Caused by: org.eclipse.aether.transfer.ArtifactTransferException:
Could not transfer artifact ch.test.sub:my-app:pom:2019.02.07 from/to
release-repo (https://nexus.intra/content/repositories/releases/):
Failed to transfer file:
https://nexus.intra/content/repositories/releases/ch/test/sub/my-app/2019.02.07/my-app-2019.02.07.pom.
The return code is 400, ReasonPhrase: Repository does not allow updating assets: releases.
The message is pretty clear but there are some things which do not add up
When initiating maven the my-app-2019.02.07.pom is not in nexus
I examined the log and there is only one "Uploading to release-repo" happening which is when the build process fails with the message above
07:54:11 [INFO] [INFO] Uploading to release-repo:
https://nexus.intra/content/repositories/releases/ch/test/sub/my-
app/2019.02.07/my-app-2019.02.07.pom
At this point, I can observe that there is a my-app-2019.02.07.pom in the Nexus repository
How does it get there when - according to the log - there was no upload happening?
pom.xml before maven is initiated
...
<parent>
<groupId>ch.test</groupId>
<artifactId>my.app</artifactId>
<version>2019.02.07-SNAPSHOT</version>
<relativePath>../pom-parent</relativePath>
</parent>
...
Version Info
Apache Maven 3.5.4
Java version: 1.8.0_201
OS name: "windows server 2016", version: "10.0", arch: "amd64", family: "windows"
I hit this issue and resolved by manually deleting the uploaded pom file, in my case it hit issues after the pom upload, causing the release to fail. Subsequent attempts at mvn release:perform then failed as that pom already existed.
Another approach to fixing this is documented here Gradle Upload Fails But Still Deploys to Nexus

Groovy grape not resolving artifacts in Maven central

Fresh install of Groovy and for some reason it isn't pulling artifacts from Maven central:
$ grape resolve org.apache.httpcomponents httpclient 4.2.1
Error in resolve:
Error grabbing Grapes -- [download failed: org.apache.httpcomponents#httpclient;4.2.1!httpclient.jar, download failed: org.apache.httpcomponents#httpcore;4.2.1!httpcore.jar, download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]
Complete -d debug log:
https://gist.github.com/mrobinet/a86073e35771cab55665
Environment:
$ groovy --version
Groovy Version: 2.4.4 JVM: 1.7.0_79 Vendor: Oracle Corporation OS: Mac OS X
The artifacts clearly exist:
https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.2/
Things I've tried:
Adding Maven Central to ~/.groovy/grapeConfig.xml
grape -r https://repo1.maven.org/maven2 resolve org.apache.httpcomponents httpclient 4.2.1
Viewing the debug output, it doesn't even appear to be requesting it from central.
I recently ran into this again and was able to figure out the issue. I ended up filing a bug with Groovy: https://issues.apache.org/jira/browse/GROOVY-8655
The problem occurs when you have only a POM file for the artifact in your Maven local repository (no jar file).

How exactly mvn -U works?

I want to know what exactly Maven do in the -U phase.
The argument ordering forced check for updates on remote repositories and if needed, updating the local maven repository with the updated dependencies used in our project.
As described:
-U --update-snapshots Forces a check for updated releases and snapshots on remote repositories
But, how exactly is this done? Is maven first of all downloading all the remote repositories and locally decides that they need to get updated, or, deciding without downloading them first? Is there some corner cases that should be known?
My Maven version is:
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T16:51:42+03:00)
Maven home: /usr/local/Cellar/maven/3.2.2/libexec
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"
It is done only for the artifacts or dependencies referenced by your project.
The last check timestamp is stored within local artifact metadata (in your local Maven repository), so Maven can apply different strategies how often to check for updates based on that. The default update interval for snapshots is "daily".
Also see updatePolicy for remote repositories in Maven's settings.xml.

Maven not working?

Initially I used maven with proxy and it was working fine. Now I don't need the proxy, so I edited the settings.xml to not use proxy. After that, Maven does not connect to the Internet to download repos. I tried reinstalling, but still getting the same problem. I even tried IDEs like eclipse and IDEA but the problem was still there. How do I resolve this?
mvn --version
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.6.0_24
Java home: /usr/lib/jvm/java-6-openjdk-i386/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-31-generic-pae" arch: "i386" Family: "unix"
mvn archetype:generate -DgroupId=org.sonatype.mavenbook.simple -DartifactId=simple -DpackageName=org.sonatype.mavenbook -Dversion=1.0-SNAPSHOT
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
Nothings happens after this.
All things considered, my initial thought is this is a connection issue since it fails to work after removing the proxy settings. Are you able to ping or curl the repository being scanned?

Resources