Not retrieving jars from maven nexus setup specific to project - maven

Got 2 Nexus maven repo - one serving or holding common jars - mostly from maven central & some others. And other - project specific maven nexus, where it holds 2 thirdparty jars which are needed for compilation of current project of interest.
Below is updates which is added to refer to local nexus maven setup & corresponding dependencies..
pom.xml snippet :
<project
...
<!-- download plugins from this *proj specific* repo -->
<repositories>
<repository>
<id>zzz-maven</id>
<name>zzz-maven</name>
<url>http://blah.blah.com/nexus/content/repositories/zzz-maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>zzz.zzz-report<groupId>
<artifactId>zzz-report<artifactId>
<version>1.2<version>
</dependency>
...
<!-- And other dependency to fetch jars from common nexus (which is working fine) -->
Added below to settings.xml (highlighted in bold text) - one covering Url to retrieve proj specific jars & other part of authenticating to proj specific Nexus
<settings>
<mirrors>
<mirror>
<id>nexus</id>
<name>Common nexus across org - Anonymous access </name>
<url>http://common-nexusxyz.com/nexus/content/repositories/maven</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
</profile>
<profile>
<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>
<!--**Added this one** -->
</profile>
<profile>
<id>zzz-maven</id>
<repositories>
<repository>
<id>zzz-maven</id>
<name>zzz-maven</name>
<url>http://blah.blah.com/nexus/content/repositories/zzz-maven</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>zzz-maven</activeProfile> <!--**activated** additional one here -->
</activeProfiles>
<servers>
<server>
<id>zzz-maven</id>
<username>userNameForZZZ</username> <!--**Specified** explicit password needed for proj specific maven nexus here -->
<password>passwordForZZZ</password>
</server>
</servers>
</settings>
But still throws out Warning & then the error for mvn install or mvn compile like :
[WARNING] The POM for zzz.zzz-report:zzz-report:jar:1.2 is missing, no dependency information available
Would like to know what is missing - so that it will download proj specific jars from proj specific maven nexus?
Tried with both <repositories> & <pluginRepositories> option in pom to consider for download
Expect it to connect to proj specific maven nexus & download dependency jar defined in pom

You have defined
<mirror>
<id>nexus</id>
<name>Common nexus across org - Anonymous access </name>
<url>http://common-nexusxyz.com/nexus/content/repositories/maven</url>
<mirrorOf>*</mirrorOf>
</mirror>
which means that all requests (due to mirrorOf having the value *) are redirected to that particular repository, no matter what other repositories are defined in the POM or the settings.xml.

Related

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.

How to fetch artifacts from own repo using maven?

How do I create a simple project that fetches artifacts from my repo using maven? And where will these artifacts get saved to - my default maven repo?
I am using Apache Archiva.
Just simply start using a repository manager like Nexus and that's it. Please configure your settings.xml file according to the following:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>URL OF your ARCHIVA SERVER</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>
The artifacts which are being downloaded are first stored into the Archiva and of course on your hard drive $HOME/.m2/repository.
If you like to deploy artifact into archiva you need to configure the distributionManagement in your pom file similar like this:
<distributionManagement>
<repository>
<id>releases</id>
<name>Archiva RElease repo</name>
<url>http://URL OF YOUR ARCHIVA/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots<id>
<name>Archiva Snapshots repo</name>
<url>http://URL OF YOUR ARCHIVA/snapshots/</url>
</snapshotRepository>
...
</distributionManagement>
...
To test this you can use mvn deploy to see if the artiacts are being deployed to the snapshot repository. You can change the version of your test project into 1.0 and redo a mvn deploy which will try to deploy the artifacts into the release repository.

Build/Deploy third-party project in maven but upload to my snapshots repository

I build weekly a large third-party project (apache sling) in Jenkins. I've got jenkin's settings.xml set up to use my own archiva server to download all dependencies (using the mirror section).
However, I haven't figured out how to get the build to upload snapshots my own snapshots repository when doing a 'deploy'. It instead tries to upload the snapshots to an apache.org snapshots server and fails.
Is there a way to configure settings.xml to override the snapshots server in a similar way it's possible to override the repository? This has to be done without editing the project's pom.xml.
The reason I need to do this is because I need access to some of the snapshot versions as dependencies in another project, and I don't want to have to manually upload them all into archiva.
Here's my 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">
<localRepository>/Users/Shared/Jenkins/.m2/repository</localRepository>
<servers>
<server>
<id>astra.internal</id>
<username>-deleted-</username>
<password>-deleted-</password>
</server>
<server>
<id>astra.snapshots</id>
<username>-deleted-</username>
<password>-deleted-</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central-proxy</id>
<name>Local proxy of central repo</name>
<url>http://-deleted-.com/repository/internal</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>snapshots</id>
<name>Local proxy of snapshots</name>
<url>http://-deleted-.com/repository/internal</url>
<mirrorOf>snapshots</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>Repository Proxy</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<!-- ******************************************************* -->
<!-- repositories for jar artifacts -->
<profile>
<!-- ******************************************************* -->
<repositories>
<repository>
<id>astra.internal</id>
<url>http://-deleted-.com/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>astra.snapshots</id>
<url>http://-deleted-.com/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
You can overwrite the Distribution management section with command line parameters.
mvn clean deploy -DaltDeploymentRepository=ui-snapshots::default::http://localhost:8081/artifactory/libs-snapshot-local/
Have a look at the maven deploy plugin.
Alternatively, you should be able to use the Jenkins post build step. There you need to specifically provide the Repo url anyway.
The location of the repository is part of the pom.xml, the distributionManagement often in one of the upper-most parents. So it is not something you can set from the settings.xml.
There's a good chance that you can change it with the distMgmtSnapshotsUrl property, see org.apache:apache:13:pom, assuming the sling-project uses this as its (indirect) parent.
As far as I know you have to edit the pom file for the project and have this section (with your server settings of course):
<distributionManagement>
<repository>
<id>archiva.internal</id>
<name>Internal Release Repository</name>
<url>dav:http://localhost:8080/repository/internal</url>
</repository>
<snapshotRepository>
<id>archiva.snapshots</id>
<name>Internal Snapshot Repository</name>
<url>http://localhost:8080/repository/snapshots</url>
</snapshotRepository>
</distributionManagement>
Would it help you to put it in a company wide pom you inherit from?

Issue pulling SNAPSHOT dependencies from Archiva snapshot repository

I've been setting up an Apache Archiva instance as both a proxy to Maven Central and to capture our development snapshots. I've managed to setup the proxy and I can deploy artifacts to the Archiva snapshot repository however I cannot pull artifacts from the snapshot repositories to use in other projects.
Relevant parts of pom.xml (dependant project)
<project>
<!-- Excluded detail -->
<dependency>
<groupId>uk.abc</groupId>
<artifactId>ABC</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<!-- Excluded detail -->
<distributionManagement>
<repository>
<id>archiva.snapshots</id>
<name>Snapshot Repository</name>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/snapshots</url>
</repository>
</distributionManagement>
<!-- Excluded detail -->
</project>
My ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>archiva.snapshots</id>
<username>username</username>
<password>xxx</password>
</server>
<server>
<id>archiva.internal</id>
<username>username</username>
<password>xxx</password>
</server>
</servers>
<mirrors>
<mirror>
<id>archiva.internal</id>
<mirrorOf>central</mirrorOf>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/internal</url>
</mirror>
<mirror>
<id>archiva.snapshots</id>
<mirrorOf>snapshots</mirrorOf>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/snapshots</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>archiva.internal</id>
<name>Archiva Managed Internal Repository</name>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>archiva.snapshots</id>
<name>Archiva Managed Internal Repository</name>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
When I build the dependant project I cannot reference classes (public access).
Just to note that I can browse the snapshots repository and I know the war file is there.
Any ideas?
It turns out that you cannot use the "war" dependency type and expect to be able to reference the contained classes. You can however create an additional jar (create both war and jar) containing the classes:
http://maven.apache.org/plugins/maven-war-plugin/faq.html#attached
You can the use the type "jar" when pulling in the dependency... in my case:
<dependency>
<groupId>uk.abc</groupId>
<artifactId>ABC</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
I think therefore the question is a bit misleading... the dependency was being pulled from Archiva but was not of an accessible type.
You are probably not activating the profile correctly
before the profile in settings.xml put something like
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
Remember this about activeByDefault
This profile will automatically be active for all builds unless
another profile in the same POM is activated using one of the
previously described methods. All profiles that are active by default
are automatically deactivated when a profile in the POM is activated
on the command line or through its activation config.
if you want to confirm if this is the issue, look at the active profiles by running help:active-profiles

Maven archetype catalog : specify custom location(s)

I'm deploying a Nexus repository for Maven, and custom archetypes on it.
I would like to execute mvn archetype:generate and be prompted a list of internal + custom archetypes.
The only way I found to prompt custom archetypes (in an ergonomic way, meaning no URL) is to define the archetype-catalog path as a property in the settings. This is not a valid solution because I want several catalogs (and this property cannot be overriden in CLI).
Does anybody have a clue on how to do that ?
Thanks in advance,
[EDIT]
I found an issue report related : http://jira.codehaus.org/browse/ARCHETYPE-273
And I noticed that during archetype:generate, maven tries to reach the central repository :
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2
It ends by a "Connection Timed out" because I did not (and don't want to) specify a proxy...
I don't understand why maven doesn't check nexus catalog...
I also have a Nexus configured to mirror the Maven repositories and thus the remote catalog too.
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://afbwt03:8081/nexus/content/groups/JavaRepo/</url>
</mirror>
and:
<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>
I am able to access the remote catalog only when I use the following Maven command line:
mvn archetype:generate -DarchetypeCatalog=http://afbwt03:8081/nexus/content/groups/JavaRepo
If I don't define the archetypeCatalog variable, I get the same behavior as you do: trying to access the repo1. ... although some mirrors are configured.
You need to have
the property archetypeRepository defined in the active profile in your .m2/settings.xml
the repositories and pluginRepositories redirected to your mirror, on the same id "central".
and of course, the mirror defined
Apache maven documentation on archetype plugin specifies that archetypeRepository is definable user property:
http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html
Your .m2/settings.xml should have these minimal elements
<?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">
<mirrors>
<mirror>
<id>central</id>
<name>Mirror for maven central</name>
<url>http://mymvnhost:8081/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>dev</id>
<properties>
<archetypeRepository>http://mymvnhost:8081/nexus/content/groups/public/</archetypeRepository>
</properties>
<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>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>
With maven-archetype-plugin:3.1.1 you have to
add/edit archetype-catalog.xml on your repo to list your custom archetypes
edit your settings.xml to add this repo with id archetype.
invoke mvn archetype:generate -DarchetypeCatalog=remote
From https://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html :
If you want the catalogs to come from a different repository, please add the following to your settings.xml
<repository>
<id>archetype</id>
<url>https://repository.domain.com/path/to/repo/</url>
</repository>

Resources