Specify Maven plugin repository from the commandline - maven

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.

Related

Overriding central works in profile, but not directly?

I've spend a lot of time looking for error in maven configuration.
I've overriden central with internal caching repository:
<activeProfiles>
<activeProfile>internal</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>internal</id>
<repositories>
<repository>
<id>central</id>
<url>https://internal.rep/nexus/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</profile>
</profiles>
However, that configuration was not working on the build server. There were attempts made to download artifacts from central maven repository.
I've found out that there, in settings.xml, the repositories section was declared directly in <settings> and not in profile:
<settings>
<repositories>
<repository>
<id>central</id>
<url>https://internal.rep/nexus/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</settings>
which I've initially ignored, because it shouldn't make any difference. It did.
But why are repositories ignored, that are defined not in profile? There was no warning about invalid settings.xml, the maven behaved as if those tags were not there...
Do generally everything in settings.xml need to be declared in profile? I'm using Maven 3.8

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>

Get dependencies from multiple repo's

Is it possible to download dependencies in maven using multiple plugin-repos?
I have my settings.xml configured to get dependencies from a custom repo and because of this, i am unable to get dependencies from the main maven repo server.
Is this possible to setup more then one plugin Repo?
Here is what i have setup so far for my custom repo:
</profiles>
<profile>
<id>custom-config</id>
<repositories>
<repository>
<id>custom-snapshots</id>
<name>customSnapshots</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:/custom/repo</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>custom-plugins</id>
<urlhttp:/custom/repo/public-snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
I have not included the dependencies here, but I am unable to pull and resolve some library dependencies.
The maven repo that I use is http://mvnrepository.com/ but I dont have details on the exact repo settings to use as the one I defined for a custom one.
The default maven repository is called "central". Its url is: http://repo1.maven.org/maven2/ or nowadays: http://repo.maven.apache.org/maven2/
But it is usually configured as mirrorOf. If you create a repository in your settings.xml and give it the id *central" it will replace it.
So I wonder why you can't resolve dependencies from there. Usually adding a repository in settings.xml does not turn of central.
could you execute mvn help:effective-settings and mvn help:effective-pom and have a loook at all repositories, profiles and mirrorOf elements in the xml? central should be there.
I would also recommend using a Maven proxy like Nexus or Artifactory. It simplifies a lot of things within a company.

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.

mvn:install to place my jar in nexus remote repository

I am using maven in eclipse (m2 eclipse)
When i execute mvn:install i want my jar(artifact) to be installed in the nexus repository which is located on the server(right now the installed jar is placed in the local system repository).. how can i do that ?
I even changed this to my local repository address
Typically, you'd use mvn deploy to deploy to a non-local repository.
You will, of course, need to have the repo configured, either in your maven settings.xml or in the project POM.
As we always use the same internal repo, I've done this in the Maven settings.xml, more precisely, the "profiles" section.
Here is my config for reference:
<profiles>
<profile>
<id>artifactory</id>
<repositories>
<repository>
<id>central</id>
<name>libs-releases</name>
<url>http://repo.example.com/libs-releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<name>libs-snapshots</name>
<url>http://repo.example.com/libs-snapshots</url>
<snapshots />
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>plugins-releases</name>
<url>http://repo.example.com/plugins-releases</url>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>

Resources