How to properly specify jcenter repository in maven config? - maven

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.

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?

Specify Maven plugin repository from the commandline

I want to use maven's dependency:get to download a package. I need to configure both a remote repository and a plugin repository. If I configure it in settings.xml it works:
(Example settings.xml from https://maven.apache.org/settings.html)
<profiles>
<profile>
...
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
...
</pluginRepositories>
...
</profile>
</profiles>
...
</settings>
mvn dependency:get -Dartifact=<artifact>
However I would like to be able to do this without configuring the settings.xml file. I know dependency:get lets you specify a -DremoteRepositories argument. There there any way to specify the plugin repository? In my particular case both repositories are actually the same location however if I only provide -DremoteRepositories maven fails to download the plugins.

Nexus group by SNAPSHOT

I have Nexus with builds repository. How I can group my versions on folders named snapshot-x.x ?
Repository have snapshot type. User deployment have all privileges.
I run maven as mvn versions:set -DnewVersion=$VERSION and mvn clean deploy -B -Pbuild -Dbuild.version=$VERSION
My settings.xml work only releases repo ;-(
<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">
<servers>
<server>
</server>
</servers>
<profiles>
<profile>
<id>build</id>
<repositories>
<repository>
<id>nexus-repo</id>
<name>Nexus repo</name>
<url>http://<MY-HOST>:8081:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-repo</id>
<name>Nexus repo </name>
<url>http://<MY-HOST>:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<altDeploymentRepository>
-DaltDeploymentRepository=builds::default::http://deployment:<MY_PASS>#<MY-HOST>:8081/content/repositories/builds
</altDeploymentRepository>
</properties>
</profile>
</profiles>
</settings>
<activeProfiles>
<activeProfile>build</activeProfile>
</activeProfiles>
I'm not sure what you are asking for? A repository has a fixed format which comprises of groupId:artifactId:version ?
There you see com/soebes/examples/j2ee is the groupId: com.soebes.examples.j2eee and than artifactId: app plus the version 1.1.2-SNAPSHOT with the underlying versions for a single SNAPSHOT

How to configure Maven to use HTTPS when connecting to repo.maven.apache.org

I would like to secure the connection to repo.maven.apache.org when resolving dependencies (I wolud like to secure all connections made by Maven actually), but I'm not used to Maven configuration... My user settings.xml contains the following repositories and pluginRepositories sections:
<profiles>
<profile>
<id>main</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo.maven.apache.org</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
However Maven is unable to resolve dependencies with that setup.
Open the file $MAVEN_HOME/conf/settings.xml (where $MAVEN_HOME is the folder in which Maven has been installed) in a text editor. Then, add the following to the <mirrors>...</mirrors> section in this file:
<mirror>
<id>central-secure</id>
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>

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