How to configure multiple repositories in Maven rightly - maven

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?

Related

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.

How to properly specify jcenter repository in maven config?

In Gradle, I need simply add:
repositories {
jcenter()
}
What is the simplest and proper way to do the same in maven pom.xml or where can I get right url for jcenter repository.
You have to define settings.xml like the following. If you define it in ~/.m2/settings.xml it will be global to your maven. If you define it as a resource of your project you can bind it with the -s parameter:
mvn -s settings.xml compile
<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray-plugins</name>
<url>https://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>
Just add a repositories section in your pom:
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
The official documentation from JFrog JCenter is in:
https://bintray.com/bintray/jcenter
Hit the SET ME UP! button on the upper right corner.

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>

maven repositories order

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

Instruct Maven to download third party plugin from https://oss.sonatype.org/content

There is a plugin I want to use on https://oss.sonatype.org/content/repositories/snapshots/
I know the maven command to run the plugin but how do I instruct Maven where the plugin should be downloaded from ?
I think I need to update my settings file to something like :
<mirrors>
<mirror>
<id>???</id>
<name>???</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</mirror>
</mirrors>
Is this correct ?
You should add a repository to your pom, that way the build will remain portable and other developers who build your code will not need to update their settings.xml.
This should do the job:
<repositories>
<repository>
<id>repo-id</id>
<name>repo-name</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
The best solution is to use the configuration in your current for only testing like this:
<project>
...
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>http://repository.apache.org/snapshots/</url>
</pluginRepository>
</pluginRepositories>
...
</project>
or change your settings appropriately like this:
<settings>
...
<profiles>
<profile>
<id>apache</id>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Maven Plugin Snapshots</name>
<url>http://repository.apache.org/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
...
</settings>
of course with activation of the profile. Or change the configuration of your repository manager.

Resources