How does Maven2 know where to find plugins? - plugins

I'm using Maven2 and I can't seem to find any plugins in my repository. I'm getting errors like
repository metadata for:
'org.apache.maven.plugins' could not
be found on repository: myrepo
where myrepo is the name of my repository.
My question is how does Maven know where to find plugins? There's a reference in my error to metadata, what metadata is expected where and what format must it take? I've not had much luck so far looking for documentation...
(I'm not interested in the easy answer to use the central repo, I want to know why myrepo isn't working.)
Thanks!

In the root of each artifact (relative path to repository root [groupId]/[artifactId]), Maven expects to find a maven-metadata.xml file. It uses this file to determine the available versions, the latest version, and the released version.
For example common-logging's metadata from repo1 lists all the available versions and tells us the release version is 1.1.1 as of 28th Nov 2008.
<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<versioning>
<release>1.1.1</release>
<versions>
<version>1.0</version>
<version>1.0.1</version>
<version>1.0.2</version>
<version>1.0.3</version>
<version>1.0.4</version>
<version>1.1</version>
<version>1.1.1</version>
</versions>
<lastUpdated>20071128191817</lastUpdated>
</versioning>
</metadata>
Maven will download the metadata for each remote repository to your local repository (with the name maven-metadata-[repo name].xml) so it can check the available versions without having to hit each repository each time. If you want to force Maven to refetch the metadata you can do so with the "-U" switch on the commandline.
If you have your own repository, it needs to publish this kind of metadata so Maven can determine if any of the versions are available is the right one. The simplest way to do this is to use a repository manager like Nexus or Artifactory which will both manage the metadata for you.

Related

What is default of repository in maven

I am new to use maven to build projects, and IDE I am using is eclipse. For projects I built before, I never used attributes <repository> in POM file and they are running very well.
But when I read some projects in github, they always come with a POM file containing quite a lot of <repository>. After reading maven official website, I know that <repositories> are location to download jar files, but I am able to import all classes only specifying <dependencies> not <repositories>.
My question is why can I download libs without specify <repositories>? Is there a default value for repositories.
Yes there is the Maven Central repository, which is automatically bundled with your pom.xml / settings.xml if you don't specify one.
You usually specify a repo in your pom.xml when you need to access an artifact that your company produces internally, or when you want to reference snapshots or the third-party company you're working with hasn't given their artifacts to Central.

Eclipse Maven Repository Browser - Could not resolve artifact

I have set up Nexus on and configured it so that it has a repository for my application and also the maven central repository exposed through a group called public and this groups is then added to my pom file:
<repositories>
<repository>
<id>repo1</id>
<name>my-repo</name>
<url>http://app1:8081/nexus/content/groups/public</url>
</repository>
I am able to browse the index both through eclipse maven repo browser and through a web browser but whenever I try and add a new dependency to the pom I get a missing dependency in my pom file and if I click on one of the jars in the maven repo browser in eclipse, even though it shows up in the tree I get an error message informing me that it could not resolve the artifact.
I want to be able to to disable the maven central mapping from within eclipse and ONLY go my Nexus server which has both maven central and my application specific repos supposedly exposed via the public group.
Can anyone help me with this configuration as currently I cannot resolve any new dependencies in any projects, I tried creating a new Spring MVC project and the only dependencies that resolved ok were the ones in my local maven respository.
Any help is appreciated.
The best way to enforce that only Nexus is used for artifact download is to set up a mirror in your settings.xml file. See here for information on how to do that:
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html

Using mvn deploy via webdav: directory creation

I managed to setup maven so it automatically uploads the latest snapshot of our software to our public maven repository.
This works fine so far, there is only a minor shortcoming that I just can not handle:
When deploying a new Snapshot, say for example:
<version>1.2-SNAPSHOT</version>
a directory named 1.2-SNAPSHOT has to be present on our webserver's maven directory, otherwise maven will fail, stating:
Failed to deploy artifacts: Could not transfer artifact ... from/to basex.mvn
(http://abc.de/webdav/): Access denied to: http://abc.de/webdav/1.2-SNAPSHOT/...
As usually when starting a new snapshot this very directory is not yet present so I end up creating it manually.
Do you have any ideas on how to come around this and make maven create this folder?
Are you sure that it is not a server side problem?
I deployed a some libraries using Webdav (over HTTPS) and first time (with directory creation) it worked.
The Pom.xml should contain a description of the distribution server.
<distributionManagement>
<repository>
<id>RepoId</id>
<name>Name of the Maven repository</name>
<url>dav:https://thewebdavurl/</url>
<uniqueVersion>false</uniqueVersion>
</repository>
</distributionManagement>
To enable directory creation, you might need to log on the server. To do this you need to add in the server part of the setting.xml the credentials for RepoId (see id of the repository in the pom).
<server>
<id>RepoId</id>
<username>login</username>
<password>pass</password>
</server>

Setup a remote FTP as a remote Maven repository?

We've been working with maven for quite some time now, and we are trying to take it to the next level...
There are a couple of Jars, that we would like to allow access to people in our organization only. So at first we all referred to the same shared folder as our local repository in the settings.xml, and it was nice for a while, when there was an individual working on a single project.
Now, we would like to have our own "Remote repository" if that is how it is called, a remote FTP that will hold the repository, with HTTP domain which points to the repository folder on that FTP.
For some reason, we can deploy Jar's, Sources and JavaDocs, but we cannot rebuild the indexes of the repository. We assume that some sort of indexing files are required, for the FTP repository, but we are unable to create these using Nexus or Artifactory. (We have something fundamentally wrong in our understanding of remote repositories)
So our question is, what are we doing wrong?
The Error we keep getting from Eclipse:
Unable to update index for repository|http://domain-referring-to-the-ftp-repository-folder
We have updated our settings.xml to:
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<localRepository>
c:\localRepository\
</localRepository>
<servers>
<server>
<username>user</username>
<password>pass</password>
<id>rep-id</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>rep-id</mirrorOf>
<name>My Repository</name>
<url>http://domain-referring-to-the-ftp-repository-folder</url>
<id>repository</id>
</mirror>
</mirrors>
</settings>
Just to be sure here are the deploy configuration which works, and deploy as described above:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<configuration>
<altDeploymentRepository>rep-id::default::ftp://x.x.x.x/repository</altDeploymentRepository>
</configuration>
</plugin>
Thanks in advance,
Adam.
Sharing local repository is really bad: local repository should be considered as private cache of Maven running on developers machine... For start, it's not concurrency safe at all, so you have to be lucky (or work on really non-interleaving projects) to not hit any problem so far with your initial setup.
Your idea about remote repository is good, but there are some problems with it's implementations. MRMs (Maven Repository Manager, both Artifactory and Nexus are MRMs and much more) will solve all your problems.
For start I'd recommend reading some of these:
http://www.sonatype.com/books/nexus-book/reference/
http://www.sonatype.com/books.html
And some blogs:
http://www.sonatype.com/people/2011/04/how-not-to-download-the-internet/
In nutshell: For transport, use HTTP for best results. Maven and MRMs have the best support for it. When having MRM, you don't need any "infra" next to it, like FS server with HTTPd or FTP daemon, since MRMs itself not just hosts your deploys, it shares them to your teammates, but also proxies, secure them, index them, etc.
From your question, it's unclear why do you deploy using FTP (none of the MRMs support FTP transport, AFAIK at least), where are your artifacts located, and many other details. Read the docos, and build up nice and cozy ecosystem for your shop!
Good luck!
Note: as Nexus lead dev, I am affiliated with Sonatype and Nexus.
Your ftp repository does not have a repository index file, which is requested by m2eclipse. Hence the message.
The message by itself is nothing to worry about. Dependencies in this repository should get downloaded, if the groupId/projectId are correctly/explicitly specified.
You may want to look at this related SO post and the link referred therein as well.

Maven local repository in CVS?

I would like to use my CVS as maven repository.. can anyone give suggestions?
There are 2 ways:
a) If you want to use it only in one project place a 'repo' directory at the toplevel. Than add jars in the maven convention (groupid in folders/artifactid/version/artifactif-version.jar).
To use this as a repository declare a file based repository in your pom.
<repositories>
<repository>
<id>some-repo</id>
<name>some-repo</name>
<url>file://${basedir}/repo</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
</repositories>
If you use this from a module pom you have to use a url relative to your module pom.
b) if you want to use it for several projects there are socalled 'wagons'. There is one for svn. These maven plugins let you use a SCM as repository. I don't know whether there is a cvs-wagon.
I would not put the dependencies in an SCM system like CVS for many reasons.
Each time you update a dependency in the pom, you need to manually add the corresponding dependency jar - in the exact same folder structure as expected by maven.
You need to worry about transitive dependencies and it can be overwhelming.
Since these dependencies do not change (except if they are SNAPSHOTS), SCM is an overkill for them. Each time there is a new version of the dependency, it needs to be in a different folder structure.
If you want to have control over the dependencies, you could create your own maven mirror using a repository manager. These store the dependencies typically using some content management libraries and can be backed up/archived.
On a related note, Maven Wagon SCM Provider can be used to publish projects to an SCM, but has not been tested with SCM based remote repository.