Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven local repository in settings.xml vs pom.xml

I am new to Maven. I would like to use the following setup:

1) a remote repository to download public artifact

2) a shared local repository for downloaded artifacts which works nicely by adding the following to settings.xml:

<localRepository>C:/m2repo</localRepository>

3) Now I would also like to have a repository for artifacts referenced from a single project, like an old-fashioned "lib" folder.

So I have added the following to the project's pom.xml:

<repository>
  <id>repo</id>
  <name>repo</name> 
  <releases>
    <enabled>true</enabled>
    <checksumPolicy>ignore</checksumPolicy>
  </releases>
  <url>${project.baseUri}repo</url>
</repository>

I have deployed some jars to the "repo" folder, but when I add them as dependencies in pom.xml, they are not resolved. Maven only looks to the shared repository and the remote repository. When I copy the contents of "repo" to the shared "m2repo", it works. Am I missing something or is this setup not possible at all?

like image 467
j_maly Avatar asked Jul 12 '13 23:07

j_maly


1 Answers

Though possible, personally I do not think that it is a good practice to do that. Depending on your usage this post will be helpful: http://blog.sonatype.com/people/2009/02/why-putting-repositories-in-your-poms-is-a-bad-idea. You also want a reproducible and portable project, this question discusses this related topic. Please don't check in those jars into your VCS just for portability sake!

I will try to help if you still insist. To make your model to work, your "repo folder" must follow the structure defined here.

Even though your "repo folder" is a local file structure, Maven will still treat it as if it is a remote repository, just like maven central. This means, whenever you are building your project, Maven will try to download the jars from your "repo folder" to your .m2 repository too:

Downloading: file:/j/my-project/my-local-repo/com/google/guava/guava/14.0.1/guava-14.0.1.pom
Downloaded: file:/j/my-project/my-local-repo/com/google/guava/guava/14.0.1/guava-14.0.1.pom (6 KB at 276.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/com/google/google/1/google-1.pom
Downloaded: http://repo.maven.apache.org/maven2/com/google/google/1/google-1.pom (2 KB at 10.4 KB/sec)

You can see that the guava jar will be downloaded from the "repo folder" to my .m2 repository since it is available from my "repo folder".

like image 66
ceilfors Avatar answered Sep 17 '22 07:09

ceilfors