Configuring Multiple Maven Repositories - maven

I have a SpringBoot project that uses maven and IntelliJ IDEA Ultimate Edition (a build automation tool used primarily for Java projects)
I have this settings.xml for maven but when I do a mvn -U clean install, only goes the the first repository to find the files
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:/Users/sandro/.m2</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
<mirror>
<id>TeamNexus1</id>
<mirrorOf>*</mirrorOf>
<name>TeamNexus1</name>
<url>http://benficiones.com:8081/nexus/content/groups/public/</url>
</mirror>
<mirror>
<id>TeamNexus2</id>
<mirrorOf>*</mirrorOf>
<name>TeamNexus2</name>
<url>http://benficiones2.com:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>p1</id>
<repositories>
<repository>
<id>TeamNexus1</id>
<name>TeamNexus1</name>
<url>http://benficiones.com:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</repository>
<repository>
<id>TeamNexus2</id>
<name>TeamNexus2</name>
<url>http://benficiones2.com:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>p1</activeProfile>
</activeProfiles>
</settings>

You defined TeamNexus1 als <mirrorOf> everything. This means that any requests, to whatever repository they go, are redirected to TeamNexus1.
This is probably not what you want.
If you want to use the two repositories in addition to MavenCentral (which is implicitly configured), you can just remove the whole <mirrors> section.

Related

How can I whitelist my private nexus on maven 3.8?

It seems like maven 3.8 has introduced some kinf of MITM attack protection, doing that it drops all the connections to the private repositories (such as nexus sonatype and so on). Here it is what happens when I try to download dependencies that are hosted into my private repository
And it stays there, waiting forever...
The private repositories are defined into the settings.xml file and everything worked perfectly (with mvn 3.6.3) until maven 3.8.
How can I put such private repositories in the "maven trusted" ones?
Here it is the settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>first-profile</id>
<repositories>
<repository>
<id>my-nexus</id>
<url>http://nexus.mycompany.com:8081/repository/dev/</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>my-nexus</id>
<username>username</username>
<password>password</password>
</server>
</servers>
<activeProfiles>
<activeProfile>first-profile</activeProfile>
</activeProfiles>
</settings>
Overriding the shipped mirror tag from /opt/maven/conf/settings.xml by placing a new variant into the user's settings.xml, only adding local repo ids to be not considered by the mirrorOf rule, worked for me.
Maven 3.8.x
<settings>
<mirrors>
<!-- a copy of /opt/maven/conf/settings.xml, so can override with exception rules -->
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>!my-repo1,!my-repo2,external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
</mirrors>
</settings>

Specify a specific repository url in maven settings.xml to deploy in Nexus

I'm a new guy on Maven and Nexus.
I have a problem to deploy my maven project (developped with IntelliJ) on my local Nexus.
You will find attached my maven settings.xml
My objective is to deploy my project without modify a pom.xml file, only the ~/.m2/settings.xml
I have tried the following command (which works) :
$ mvn clean deploy -DaltDeploymentRepository=nexus::default::http://192.168.1.8:8081/repository/maven-snapshots
But I want the same results with only :
$ mvn clean deploy
Any idea ?
Thanks
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.8:8081/repository/maven-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>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>******</password>
</server>
</servers>
</settings>
You can add a <properties> section to your settings.xml and add
<altDeploymentRepository>nexus::default::http://192.168.1.8:8081/repository/maven-snapshots</altDeploymentRepository>

How to avoid from using the defined mirror with a different profile in Maven?

My project at work is using an Artifactory as mirror of Maven. So there is the following setting in ~/.m2/settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>artifactory</id>
<username>rx</username>
<password>67CoHEdAxq6PALFzoB</password>
</server>
</servers>
<mirrors>
<mirror>
<id>artifactory</id>
<mirrorOf>*</mirrorOf>
<url>https://dev.mycompany.com/artifactory/maven-all</url>
</mirror>
</mirrors>
</settings>
As a result, all the repositories will download dependencies or plugins from the mirror: https://dev.mycompany.com/artifactory/maven-all. However, I need to develop my own projects on the same PC without using the mirror but only the maven central repository, https://repo.maven.apache.org/maven2. So I intend to use a profile, inside which the repository has a unique id, private, then make use of <mirrorOf>*,!private</mirrorOf> to be prevented from using the Artifactory mirror. The changed settings.xml looks like this:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>artifactory</id>
<username>rx</username>
<password>67CoHEdAxq6PALFzoB</password>
</server>
</servers>
<mirrors>
<mirror>
<id>artifactory</id>
<mirrorOf>*,!private</mirrorOf>
<url>https://dev.mycompany.com/artifactory/maven-all</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>private</id>
<repositories>
<repository>
<id>private</id>
<id>https://repo.maven.apache.org/maven2/</id>
</repository>
</repositories>
</profile>
</profiles>
</settings>
Problem: when making use of the profile private to generate a project with the following command:
mvn -P private archetype:generate -DgroupId=rx.practice.servlet -DartifactId=servlet -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=fa[Clse
Maven still tries to download the plugin from the mirror, where does not contain those plugins. Anyone can explain why? and How to fix it?

kiescanner does not detect updated kjars at remote maven nexus repository

I have a spring-boot application (myapp) with drools the kie-ci module enabled (the drools version i use i the 7.13.0.Final).
I also host my kjars to a remote nexus maven repository.
KieScanner is not fully operative with remote nexus repository.
At the time of project building for first time, all the κjars are detected and downloaded in my local maven repo but when myapp is running the remote updated kjars are not detected by kiescanner.
When i manually delete the local kjars from the .m2 repository, then the latest kjars are downloaded locally and kiescanner detects them.
Seems to be more a maven issue than a drools issue.
My settings.xml maven file is the following:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central</id>
<name>central</name>
<url>http:///XXX.XXX.X.ΧΧ:8081/repository/maven-group/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>maven-snapshots</id>
<url>http://XXX.XXX.X.ΧΧ:8081/repository/maven-snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
and i execute myapp by the following format:
java -jar -Dspring.profiles.active=myprofile target/myapp-0.0.1-SNAPSHOT.jar
How i can make myapp to detect remote nexus updated kjars dynamically?
Thank you very much for you time!

Nexus public repository index not picking up un-indexed repositories

I setup a public repository in nexus which contains the groups of repositories we wish to access. We then use this as our main index in Eclipse for development and Bamboo for build.
I am adding in a couple of ZK repositories to this public repository - these repos have no indexes, and are unable to be scraped by Nexus. I presume this will prevent artifacts in them from being found. I have rebuilt the index for public in Nexus and in Eclipse with no luck.
Can I add the repositories in the setting.xml in eclipse? Currently this looks like the following:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<id>nexus</id>
<username>username</username>
<password>xxxx</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://<ip>:8400/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>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Search indexes are an optional repository feature. They are not used for artifact retrieval, they are used to support interactive search in UI's. Nexus will be able to pull artifacts from these proxy repositories without any problem. As artifacts are downloaded from the remote into the proxy repository's disk cache they will be added to the local search index.

Resources