kiescanner does not detect updated kjars at remote maven nexus repository - maven

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!

Related

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>

Private Maven Repository in Closed Network

I am in a closed network, do not have access to http://repo.maven.apache.org We set up a Nexus server and we download all of our .m2's on a publicly accessible computer, burn to disk, then upload to our Nexus server (inefficient but necessary)
Currently I am trying to set up the system to only use my nexus server, currently it tries to go to http://repo.maven.apache.org
(assuming is set to false) If I have set to true, it does not even attempt to go to my private repo. Basically, I just need my Maven to only look at my nexus instance, not even attempt to go to http://repo.maven.apache.org
Here are portions of my settings.xml and pom.xml files:
<!-- Settings.xml in my .m2 directory -->
<offline>true</offline>
<servers>
<server>
<id>mynexus</id>
<username>xxx</username>
<password>xxx</username>
</server>
<server>
<id>mynexusplugins</id>
<username>xxx</username>
<password>xxx</username>
</server>
</servers>
<!-- pom.xml -->
<repositories>
<repository>
<id>mynexus</id>
<url>http://192.168.100.4:8081/....</url>
</repository>
</repository>
<pluginRepositories>
<pluginRepository>
<id>mynexusplugins</id>
<url>http://192.168.100.4:8081/....</url>
</pluginRepository>
</pluginRepository>
Add your repository as mirror of all in the settings.xml, this way it won't look any other repo.
<mirrors>
<mirror>
<id>yourRepo</id>
<name>yourRepo name</name>
<url>your url</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
https://maven.apache.org/guides/mini/guide-mirror-settings.html
As a side note, If you set offline in maven(via command line or config) it will only use local m2 folder.

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.

Is there such a thing as a local remote Maven repository?

I have a build box on which is installed:
Maven
Bamboo
Archiva
I have configured Bamboo to grab my Maven project from a remote Git source and then build it with the goals 'clean install'.
I have configured Archiva with two repos:
mirror - a mirror of central
dev - repo for my artifacts
I have made the following changes to Maven settings.xml:
# Define local repo - this is the same location as i have set up for the Archiva 'dev' repo.
<localRepository>/opt/maven-repo/dev</localRepository>
# Define the Archiva mirror i set up
<mirror>
<id>mirror</id>
<url>http://localhost:8080/repository/mirror/</url>
<mirrorOf>external:*</mirrorOf>
</mirror>
When I execute the build Maven grabs everything external via the mirror and then adds the built artifact to dev, along with the other jars it grabbed from mirror. So i now have some duplicate jars...
\repo\mirror\junit\junit
\repo\mirror\classworlds\classworlds
\repo\dev\junit\junit
\repo\dev\classworlds\classworlds
\repo\dev\me\myartifact
My question is, is the correct approach? Really I want to keep 'dev' with just my artifacts and mirror with everything from central - i don't want duplicates.
Should I be using the LocalRepository config in settings.xml or should I be using 'mvn deploy' to put the artifact in my Archiva repository by a different method?
Could someone clarify the different use cases for a local and remote repository?
Finally, how should I be defining my POM? Currently, I have just defined
<distributionManagement>
<repository>
<id>dev</id>
<url>file:///repo/dev</url>
</repository>
</distributionManagement>
Should i be adding in my mirror?
To put artifacts in your repository manager you should use the default which is maven-deploy-plugin which can be controlled by distributionManagement. The target where to put those things is controlled by defining the distributionManagement.
<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/xsd/maven-4.0.0.xsd">
...
<distributionManagement>
<repository>
<id>releases</id>
<name>Release</name>
<url>http://urlArchiva/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://urlArchiva/snapshots/</url>
</snapshotRepository>
...
</distributionManagement>
...
</project>
The repositories which are used to consume artifacts from is defined in the settings.xml
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://serverUrlArchiva/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<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>
On Bamboo you should be able to control which settings.xml is used to have an local repository per build which makes build independent from each other.

Configuring Maven to use Central Repository if Nexus is unreachable

I've run into a situation where configuring Nexus as a Mirror for everything doesn't quite suit my needs. My Nexus repository is behind a VPN. If I can't access the Nexus repository, I can't build anything because it's configured as a Mirror. What if I want to build a project that has no dependencies on my Nexus repository yet I can't access it? This would build fine by simply using the Central repository but it won't look there because of the Mirror.
Does anyone have any ideas on how to get around this? I think ideally I'd like to look at Nexus first but if it's not accessible I'd like to look at the Central repository. I'm also open to any other suggestions for achieving the same goal that anyone may have.
you need to configure multiple repositories
http://maven.apache.org/guides/mini/guide-multiple-repositories.html
maven-3.0.4\conf\settings.xml file could be configured this way:
<?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">
<pluginGroups />
<proxies />
<servers>
<server>
<!-- local repository have restricted access -->
<id>central</id>
<username>myusername</username>
<password>mypassword</password>
</server>
<server>
<id>LocalRepository</id>
<username>myusername</username>
<password>mypassword</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>external:*</mirrorOf>
<name>Central</name>
<url>url to repository</url>
</mirror>
<mirror>
<id>LocalRepository</id>
<mirrorOf>LocalRepository</mirrorOf>
<name>repository</name>
<url>url to repository</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>central</id>
<repositories>
<repository>
<id>central</id>
<name>Central</name>
<url>http://central/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>LocalRepository</id>
<name>specific repository</name>
<url>repository URL</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>central</activeProfile>
</activeProfiles>
</settings>
The best approach for this kind of requirement is to run Nexus locally on your development machine.
Its easy to install and run and you can just always point to it.
Configure it to proxy your corporate Nexus and Central.
Then when you are off the VPN .. the corporate proxy repo will just be unreachable but you still get anything else just fine. Nexus manages it all for you.
I have been doing this for years and it allows me to switch to different contexts all the time very easily. It is a bit of a standard practice for many Maven users in fact and should be for other tools that use remote repositories like Gradle or SBT as well. Makes things a LOT easier.

Resources