I am just trying to understand the logic behind custom remote repositories with Maven. In one experiment (in OS X, using the command line) I am declaring a remote repository in a POM like this: (in fact is not really remote, since I am using file:///...):
<repositories>
<repository>
<id>myRepository</id>
<url>file:///test_mvrepository/repository</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
This POM also declares a dependency on certain artifact X (the JPL library in my example), that is present only in the 'remote' repository, not in the local one:
<dependencies>
<dependency>
<groupId>jpl</groupId>
<artifactId>jpl</artifactId>
<version>[3.1.4-alpha,]</version>
</dependency>
...
</dependencies>
When I execute this:
mvn package
The project is built as expected only once. If I repeat the operation I will have a message saying that my artifact X is not accessible:
[ERROR] Failed to execute goal on project projectname: Could not resolve dependencies for project groupid:artifactid:jar:0.0.1-SNAPSHOT: Could not find artifact jpl:jpl:jar:3.1.4-alpha -> [Help 1]
Here is the complete POM:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>repId</id>
<url>file:///test_mvrepository/repository</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>jpl</groupId>
<artifactId>jpl</artifactId>
<version>[3.1.4-alpha,]</version>
</dependency>
...
</dependencies>
</project>
After some debugging I found out that, though I did not install the POM with mvn install
, the artifact X is in the local repository (its POM, jar and additional files). Only if I delete the entry from my local repository I could repeat the operation again without getting the error message.
In fact, I do not have to delete all the entry in the local repository, just the file maven-metadata-local.xml
. This is how this file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>jpl</groupId>
<artifactId>jpl</artifactId>
<versioning>
<release>3.1.4-alpha</release>
<versions>
<version>3.1.4-alpha</version>
</versions>
<lastUpdated>20111214230431</lastUpdated>
</versioning>
In my remote repository that file is called maven-metadata.xml
.
Finally, if instead I type
mvn install
Then X is always accessible as expected, not only once as in the previous case.
I cannot understand the logic of this. Why I cannot ask Maven to package my artifact many times in this setting?. For me is evident that if I am not installing it in the local repository, then it should go again and again to the remote repository. Or at least, it should install the necessary objects in the local repository in a way that I can refer to them later, instead of blocking all future package
requests until I manually delete the entry? Is this a bug in Maven ? thanks for any clarification !
Update: In case it is important, this is how I built my test scenario:
I installed in my local repository the JPL library (its dependency is the one that is giving me problems). I did it with this command:
mvn install:install-file -Dfile=jpl.jar -DgroupId=jpl -DartifactId=jpl -Dversion=3.1.4-alpha -Dpackaging=jar
I copied the local repository to a new location in the file system (my 'remote' repository), and in this new location I changed the name of the
maven-metadata-local.xml
of the JPL entry to justmaven-metadata.xml
, as explained here: http://www.javaworld.com/community/node/3968.I deleted from my local repository the JPL entry.