Peculiar Maven Repository Resolution Problem - maven-3

I am facing a strange phenomena related to Maven repository resolution (Maven version: 3.8.4) which I am unable to explain. The matter is as follows:
We have a internal Nexus proxy setup for Central Repository. The URL is http://[companyDomain]:8081/repository/maven-central
I am declaring a repository in the pom.xml as follows:
<repository>
<id>nexus-maven-central</id>
<name>Maven Central Repository Internal Proxy</name>
<url>http://[companyDomain]:8081/repository/maven-central</url>
<layout>default</layout>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
The effective pom is showing the above repository as the first in the list of repositories and default Maven Central repository (id:central) after that as it should be.
However, when I build the pom, Maven is directly going to the Maven Central repository, not considering the above repository.
Now, when I start a Nexus instance in my local host and change the above URL to:
http://localhost:8081/repository/maven-central
Maven resolves the repository and downloads from the localhost.
Further, when I use the http://[companyDomain]:8081/repository/maven-central again in the pom and this time configure a mirror in the global setting.xml (I am not using user specific settings)
<mirror>
<id>nexus-maven-central-mirror</id>
<name>Mirror for Maven Central Repository</name>
<url>http://[companyDomain]:8081/repository/maven-central</url>
<mirrorOf>central</mirrorOf>
</mirror>
Maven perfectly resolves the internal proxy repository and downloads artifacts.
As for the environment, I am connecting to the corporate network through a VPN. IP of the internal Nexus server is resolvable when I am connected to the VPN; there are no VPN outages when I am trying the above.
I was expecting Maven to at least try the internal proxy repo when configured with the 'downloading from ...' message, nothing of that nature shows up in the console. It goes directly to Central Repository.
I further tested with the following URLs:
http://repo1.maven.org/maven2/ ---> Does Not Work
https://repo1.maven.org/maven2/ ---> Works
While I am aware that Maven does not prefer to download from 'http' and Maven Central explicitly states that it will send error if accessed over http, then the question is why is it downloading from localhost on http and not remote; does Maven have this behaviour of ignoring remote http.
Or are the 'localhost' and remote repos treated differently by Maven. Or are there some other matter I am missing.
I, unfortunately could not unearth much documentation on the above; any help would be appreciated.

The first thing is: I am declaring a repository in the pom.xml as follows:
If you use a repository manager always define the repositories via the settings.xml like this:
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>https://central</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://central</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
Remove all repository entries from your pom files...

Related

Missing artifact com.epam.reportportal:agent-java-testng:jar:5.0.4

While integrating the report portal with your testng project, we need epam.reportpotal dependencies, On adding the reportportal dependency I am facing the following error in pom.xml dependency :
it says : Missing artifact com.epam.reportportal:agent-java-testng:jar:5.0.4
To resolve this you need to add the following repositories in your pom.xml file as mentioned on github(https://github.com/reportportal/agent-java-testNG)
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-epam-reportportal</id>
<name>bintray</name>
<url>http://dl.bintray.com/epam/reportportal</url>
</repository>
</repositories>

Create local remote repository using Maven

I am using Maven for build and Jenkins for CI/CD. For production, need to keep all my Maven build jars in my remote repository, I am adding my local repository by
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>http://10.16.70.55:9001/var/lib/jenkins/.m2/repository</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>http://10.16.70.55:9001/var/lib/jenkins/.m2/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
Is this the correct way? Does Jenkins provide remote repository? Is there any other tools which we can use?
Have you looked at using an actual repository manager tool like Nexus OSS or JFrog Artifactory ?

Build and Deploy a Maven Project to Nexus via Jenkins

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.

How to get the list of jars downloaded from a specific repository out of many defined in pom.xml

I have the following repositories defined in my pom.xml.
<repositories>
<repository>
<id>spring-maven-release</id>
<name>Spring Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
<repository>
<id>spring-maven-milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>spring-roo-repository</id>
<name>Spring Roo Repository</name>
<url>http://spring-roo-repository.springsource.org/release</url>
</repository>
<repository>
<id>xxxx-repo.snapshot</id>
<name>iGV Snapshot Repository</name>
<url>http://mavenrepo.XXXX.com/maven2</url>
</repository>
Is there a way to know the jars that are downloaded from http://mavenrepo.XXXX.com/maven2 in the above pom.xml?
Yes you can check by following steps:
Right click on project explorer folder n click on new.
Click on others,select maven new project.
Click next,choose default work-space.
Now you can see list of archetypes these are nothing but dependencies that comes with maven.

Maven cannot for life download maven-plugin-descriptor-2.0.6

Basic info:
I use embedded Maven 3.0.4 in Eclipse Juno (with JBoss Tools).
settings.xml (straight from community.jboss.org/wiki/MavenGettingStarted-Users):
<profile>
<id>jboss-public-repository</id>
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>jboss-public-repository</activeProfile>
<activeProfile>jboss-deprecated-repository</activeProfile>
</activeProfiles>
Note: I tried also repository.jboss.org/nexus/content/groups/jboss and repository.jboss.org/nexus/content/groups/public/ with same results.
What I did:
I created Maven project from scrath using artifact org.jboss.spec.archetypes jboss-javaee6-webapp. System try to download repos. Everything downloads fine except two POMs:
maven-plugin-descriptor-2.0.6.pom
plexus-2.0.2.pom
I will focus on maven-plugin-descriptor, but plexus behave identically.
Error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.5:resources (default-resources) on project example:
Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.5:resources failed:
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved:
Failed to collect dependencies for org.apache.maven.plugins:maven-resources-plugin:jar:2.5 ():
Failed to read artifact descriptor for org.apache.maven:maven-plugin-descriptor:jar:2.0.6:
Could not transfer artifact org.apache.maven:maven-plugin-descriptor:pom:2.0.6 from/to central (repo.maven.apache.org/maven2):
No response received after 60000 -> [Help 1]
Requested file is not present at all in repository.jboss.org/nexus/content/groups/public-jboss/org/apache/maven/maven-plugin-descriptor/2.0.6/ (returns 404).
I tried to go to repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-descriptor/2.0.6/ directly in browser. File maven-plugin-descriptor-2.0.6.pom is present, but after click it thinks... thinks... thinks... aaand connection reset. Note that many other POMs was downloaded from repo.maven.apache.org without problems. Only this file for some reason Just Don't Work(TM).
Other:
I am NOT behind proxy. I DID use "delete whatever.lastUpdated" trick. Even deleted entire repo to force downloading everything again. Did not work, of course.
Any ideas? Or maybe I am barking at wrong tree and some other repository must be set in settings.xml? I have impression that maven tries to download too old versions...
Problem was solved. If someone have similiar problem to mine, he have to use mirrors.
In settings.xml:
<settings>
...
<mirrors>
<mirror>
<id>uk.maven.org</id>
<mirrorOf>central</mirrorOf>
<name>UK Central</name>
<url>http://uk.maven.org/maven2</url>
</mirror>
</mirrors>
...
</settings>

Resources