Difference between repository and pluginrepository - maven

My Android Maven project pom.xml contains the following entries. Now everything works fine. What is the difference between <repositories> entries and the <pluginRepositories> entries.
<repositories>
<repository>
<id>my-repo</id>
<url>http://10.10.10.230:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>my-repo</id>
<name>my-repo</name>
<url>http://10.10.10.230:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

As #otakun85 stated, There is no technical difference at all. It's for having different configurations->behavior for plugins in contrary to normal artifacts. See repository vs. pluginRepository for more details.
Also check maven-users mailing list archives, It provides quite good explanation to it.

Maven will resolve plugin dependencies using the configured pluginRepository. Other artifact dependencies (eg. a parent pom) are resolved using repository.
Note: Things available on maven central will be resolved by default so you wouldn't normally need to include repository for those.
For example, if your pom.xml specifies a parent pom and a plugin dependency that both exist in the same repository you must still specify both repository AND pluginRepository. If you only configure one then maven will complain with "Unresolvable X" errors.

Related

Understanding Maven tags

I was using maven in my project, most of the cases I used only dependency tags, but this time I have below tags in use:
<repositories>
<repository>
<id>myrepo</id>
<name>REPO</name>
<url>http://host:8081/nexus/content/repositories/repo/</url>
<layout>default</layout>
</repository>
<repository>
<id>thirdparty</id>
<name>THIRD</name>
<url>http://host:8081/nexus/content/repositories/thirdparty/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>repo-snapshots</id>
<name>REPO-SNAPSHOTS</name>
<url>http://host:8081/nexus/content/repositories/snapshots/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>repo1-snapshots</id>
<name>REPO1-SNAPSHOTS</name>
<url>http://host1:8081/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>myplugin</id>
<name>MY-PLUGIN</name>
<url>http://host:8081/nexus/content/repositories/central/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>distr</id>
<name>DISTR</name>
<url>http://host:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>distr</id>
<name>DISTR</name>
<url>http://host:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
I know that repositories is used to configure our remote repositories.
1) But what is the use of releases --> enabled = true indicates
2) also what it indicates when we say snapshots --> enabled=true instead of using releases.
3) Also what it indicates if we say updatePolicy=always and what happens if we do not mention this.
4) What is the use of pluginRepositories here? also the inner releases tag
5) What is the use of distributionManagement and its inner tags repository and snapshotRepository?
1) This means that Maven searches release versions (aka non-SNAPSHOT versions) in this repository.
2) Maven searches SNAPSHOT versions in this repository.
The distinction between (1) and (2) exists because if you do not have repository groups, you usually have different repositories for the different types.
3) This means that SNAPSHOTS are always (read: every build) updated from remote repositories. The standard policy is to cache downloaded SNAPSHOTs for one day (so triggering another build on the same day would not again download the newest SNAPSHOT).
4) These repositories are purely used for the dependencies of your plugins.
5) These are used to deploy artifacts you build yourself.

How maven handle multiple <repository> configurations?

I am getting more and more comfortable with maven. But still some questions.
I have multiple <repository> in my pom.xml.
How will maven handle these repos when downloading artifacts? Will it search by the declaration order?
Besides the explicitly declared ones, will maven still check the default central repo at http://repo.maven.apache.org/maven2/?
If something cannot be found within the explicitly configured repo, will maven fallback to the default central repo?
Is it good to use multiple repos? I am kind of worried about inconsistency.
Below is the <repositories> section of my pom.xml:
<repositories>
<repository>
<id>ibiblio-central-repo</id>
<layout>default</layout>
<name>ibiblio-central-repo</name>
<releases>
<checksumPolicy>warn</checksumPolicy>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://maven.ibiblio.org/maven2/</url>
</repository>
<repository>
<id>oschina-central-repo</id>
<layout>default</layout>
<name>oschina-central-repo</name>
<releases>
<checksumPolicy>warn</checksumPolicy>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://maven.oschina.net/content/groups/public/</url>
</repository>
<repository>
<id>oschina-central-repo-3rd-party</id>
<layout>default</layout>
<name>oschina-central-repo-3rd-party</name>
<releases>
<checksumPolicy>warn</checksumPolicy>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://maven.oschina.net/content/repositories/thirdparty/</url>
</repository>
</repositories>
How will maven handle these repos when downloading artifacts? Will it
search by the declaration order?
Order of declaration as part of the merged settings (see next answer). I have found this JIRA ticket providing further details.
Besides the explicitly declared ones, will maven still check the
default central repo at http://repo.maven.apache.org/maven2/?
Yes, as it will be provided by the Maven super POM, implicit parent of all Maven Pom (here an official example), unless specified in your settings.xml (if you override the repository id specified in the super POM). You can use the Maven Help Plugin to get the effective settings Maven will apply to your build and the effective pom maven will actually (effectively) run.
As documented here, the repositories element is inherited.
If something cannot be found within the explicitly configured repo,
will maven fallback to the default central repo?
As above. Moreover, you could also influence this mechanism via any configured Maven mirror. You could, for instance, redirect Maven to your company repository (see below) instead of looking up on the default one.
Is it good to use multiple repos? I am kind of worried about
inconsistency.
You probably don't need many configured repositories, but you might need more than one if the dependencies you are looking for are not provided by the default repository. A good approach would be to have an enterprise Maven repository (i.e. Artifactory, Nexus) and make your local settings only point to it. Then, configure the internal Maven repository to point to other repositories, in a centralized (and governed) manner.

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.

Maven: Warning if dependency if artefact is not found

Can I add option to Maven to say WARNING if some artefact wasn't found in some repository. Let's I have
<repositories>
<repository>
<id>main</id>
<name>main-repo</name>
<url>http://repourl</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
But Maven not find some dependency of dependency in repo. Then he say WARNING in log. Can I do it?
A have in my company's repo resource 'org.apache.cxf:cxf-rt-frontend-jaxrs:pom:2.5.4'. But I havn't dependencies. This resource was copied to my JAR file. But no one dependency of 'cxf-rt-frontend-jaxrs' wasn't intsalled. In log
[INFO] Unable to find resource 'org.apache.cxf:cxf-rt-frontend-jaxrs:pom:2.5.4' in repository MAIN (http://url/)
Downloading: http://url//org/apache/cxf/cxf-rt-frontend-jaxrs/2.5.4/cxf-rt-frontend-jaxrs-2.5.4.pom
But no warning about dependencies of cxf-rt-frontend-jaxrs
Dependencies of cxf-rt-frontend-jaxrs are declared in org.apache.cxf:cxf-rt-frontend-jaxrs:pom:2.5.4 artifact, which Maven was not able to find. So, answer to your question is it can't be done.

Maven repository lookup order

We have an internal Apache Archiva based repository and we have configured the repositories tag in pom.xml to be as follows. Can I assume that all dependency access will get resolved by internal repository if you have access to it and will get resolved by other repositories listed below, if internal repository is down for a certain reason.
<repositories>
<repository>
<id>internal</id>
<name>Internal Repository</name>
<url>http://192.168.1.2/archiva/repository/internal</url>
</repository>
<repository>
<id>jboss</id>
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
....
</repositories>
EDIT:
I want to do away with the .m2/settings.xml file. I want to define this in my pom.xml file, so that if my repository manager is UP and running I would want the runtime to connect there, else would want to fallback into the other repositories. Would this be possible?
Maven 3.0 had it fixed as you can see in Maven developer's Jira below. The lookup will be done in the order they are declared.
https://issues.apache.org/jira/browse/MNG-4400

Resources