maven repositories order - maven

I have a maven repo which stores all the artifacts under
http://example.com/content/public
I have a second repo which stores different artifacts under
http://example.com/content/type1
By default for all the builds I want to get the artifacts from "content/public"
But for one specific usecase when a flag is switched on I want to get artifacts from "content/type1"
If an artifact is not present then I want to look for it in "content/public"
My apache-maven/3.04./conf/settings.xml looks like this
<mirrors>
<mirror>
<!-- This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*,!type1</mirrorOf>
<url>http://example.com/content/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><updatePolicy>never</updatePolicy></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<!-- Default this property so we can create references easily. -->
<nexusHostName>example.com</nexusHostName>
</properties>
</profile>
</profiles>
<activeProfiles>
<!-- make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
My profile in the pom.xml looks like this
<profile>
<id>type1-build</id>
<activation>
<property>
<name>type1</name>
<value>true</value>
</property>
</activation>
<repositories>
<repository>
<id>type1</id>
<name>Type1 Repo</name>
<url>http://${nexusHostName}/content/groups/type1/</url>
<layout>default</layout>
<!-- Enforce strict checksums and always update releases and snapshots -->
<releases>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>nexus</id>
<name>Nexus</name>
<url>http://${nexusHostName}/content/groups/public/</url>
<layout>default</layout>
<!-- Enforce strict checksums and always update releases and snapshots -->
<releases>
<enabled>false</enabled>
<checksumPolicy>fail</checksumPolicy>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
Even after doing this when i run a goal like mvn goal1 -Dtype1=true it still looks for artifacts in "content/public"
Can someone please tell me what is that I am doing wrong

Just change the order of your repositories content/type1 first and then content/public

Related

How to configure multiple repositories in Maven rightly

I need to add fast-md5 to dependencies which lays at https://repo.spring.io/plugins-release/, so I configure settings.xml like
<profiles>
<profile>
<id>main</id>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>centralx</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>spring</id>
<url>https://repo.spring.io/plugins-release/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>main</activeProfile>
</activeProfiles>
But now all dependencies are missing. The error message is
Missing artifact commons-io:commons-io:jar:2.5
So How to configure multiple repositories?

Moving maven profiles in setting.xml to pom.xml

I am using maven3. I have some user specific profiles and activeProfiles tags defined in settings.xml and I want to move them to project's pom.xml.
But merely copying profiles and activeProfiles from settings.xml to pom.xml does not work and breaks build because it tries to find project's parent pom in maven central instead of artifactory. Here's my settings.xml profiles.
Maven reports problem:
Failure to find xxx:xxx:pom:19.2 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Can someone please help ?
{
<profiles>
<profile>
<id>group</id>
<repositories>
<repository>
<id>nb_releases</id>
<name>Releases</name>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://artifactory.xxxx.xxxx/nb-m2</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
<profile>
<id>snapshots-group</id>
<repositories>
<repository>
<id>nb_snapshots</id>
<name>Snapshots</name>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://artifactory.xxxx.xxxx/nb-m2-snapshot</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
<profile>
<id>plugins</id>
<pluginRepositories>
<pluginRepository>
<id>nb_plugins</id>
<name>Plugins</name>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://artifactory.xxx.xxx/nb-m2</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>group</activeProfile>
<activeProfile>snapshots-group</activeProfile>
<activeProfile>plugins</activeProfile>
</activeProfiles>
}
The tag <activeProfiles> can only be used in the settings.xml, not in the POM.
There are different possibilities to activate a profile which can be used in a POM:
https://maven.apache.org/guides/introduction/introduction-to-profiles.html

How to use Spring Snapshots with Nexus Repository

We have no problem building Spring Boot RELEASE projects with our Nexus repository which proxies maven-central and use a maven-public group. A Spring Boot SNAPSHOT project won't build, because Maven cannot resolve the SNAPSHOT dependencies. Spring SNAPSHOTS get downloaded, but then we get this error message.
Failure to find org.springframework.cloud:spring-cloud-starter-zipkin:jar:2.2.0.BUILD-SNAPSHOT
in http://[host]:8081/repository/[snapshots] was cached in the local
repository, resolution will not be reattempted until the update
interval of [snapshots] has elapsed or updates are forced
Here are the settings:
<settings>
<mirrors>
<mirror>
<id>nexus-proxy-maven-central</id>
<name>maven-central</name>
<url>http://[host]/repository/maven-central</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://[host]/repository/maven-public</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestone</id>
<name>Spring Milestone Repository</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
<pluginRepository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://[host]/repository/maven-public</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<servers>
<server>
<id>[snapshots]</id>
<username>*</username>
<password>*</password>
</server>
<server>
<id>[releases]</id>
<username>*</username>
<password>*</password>
</server>
<server>
<id>maven-public</id>
<username>*</username>
<password>*</password>
</server>
<server>
<id>maven-central</id>
<username>*</username>
<password>*</password>
</servers>
</settings>
The pom looks like this:
<distributionManagement>
<repository>
<id>[releases]</id>
<url>https://[host]/repository/[releases]/</url>
</repository>
<snapshotRepository>
<id>[snapshots]</id>
<url>https://[host]/repository/[snapshots]/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>repository.spring.snapshot</id>
<name>Spring Snapshot Repository</name>
<url>http://repo.spring.io/snapshot</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>repository.spring.milestone</id>
<name>Spring Milestone Repository</name>
<url>http://repo.spring.io/milestone</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>[releases]</id>
<name>[releases]</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots><enabled>false</enabled></snapshots>
<url>http://[host]/repository/[releases]</url>
<layout>default</layout>
</repository>
<repository>
<id>[snapshots]</id>
<name>[snapshots]</name>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
<url>http://[host]/repository[snapshots]</url>
<layout>default</layout>
</repository>
</repositories>
I've trying building with and without a Nexus proxy for Spring Snapshots, but it didn't help.
The problem is that 2.2.0.BUILD-SNAPSHOT is not publically available at http://repo.spring.io/snapshot at this time. The highest version available is 2.1.2.BUILD-SNAPSHOT. I was working with a Pivotal employee who must have access to higher build numbers earlier than the public. I backed my pom.xml down to 2.1.1.RELEASE and it worked.

cannot download snapshot from nexus

I set up a nexus repo for maven, I have deployed a snapshot but I can't get it anyway. No problem on release version.
Snapshot in the repo
what I get in my local repo
cannot get the jar
can get the metadata
Maven Setting
<mirror>
<id>maven-public</id>
<mirrorOf>*</mirrorOf>
<name>maven-public</name>
<url>http://nexus:8081/repository/maven-public/</url>
</mirror>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>public</id>
<name>maven-public</name>
<url>http://nexus:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<url>http://nexus:8081/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
If the metadata is getting cached . try using mvn -U to the update the cached local repository.

Maven FTP repository

I have setup a maven repository on my webserver using FTP.
The deployment works as expected, but when I wnat to install a submodule it does not find the files on the webserver, because it is trying to download from a wrong location.
I have setup the maven repo with a folder for snapshots and one for releases:
/ftp-dir/
releases/
snapshots/
The root pom file has fllowing distributionManagement:
<distributionManagement>
<repository>
<id>repo-id</id>
<url>ftp://my-ftp/releases</url>
</repository>
<snapshotRepository>
<id>develman.repository</id>
<url>ftp://my-ftp/snapshots</url>
</snapshotRepository>
</distributionManagement>
If I run mvn deploy with a -SNAPSHOT version it deploys the files into the snapshots directory as expected.
But when I delete my local repository and try to install a submodule maven cannot find the artifact. My settings.xml looks like this:
<servers>
<server>
<id>repo-id</id>
<username>username</username>
<password>password</password>
</server>
</servers>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>repository-id</id>
<name>my repository</name>
<url>http://my-website-address.com</url>
<layout>default</layout>
<releases>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
aven tries to download from http://my-website-address.com/... and not from http://my-website-address.com/snapshots as expected.
What is my problem?
I had to change my repositories definition to two seperate repositories (1 for snapshot, 1 for release):
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>repository-release-id</id>
<name>my release repository</name>
<url>http://my-website-address.com/releases</url>
<layout>default</layout>
<releases>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</repository>
<repository>
<id>repository-snapshot-id</id>
<name>my snapshot repository</name>
<url>http://my-website-address.com/snapshots</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>

Resources