How to use Maven with no shared repository

On the projects I work on, I always try to introduce Maven. Unfortunately, it is often impossible to get approval for a separate machine to be used as a repository. For open source packages, that is not really a problem as they are available on the usual public repositories. But some are not, so I often end up using my workstation as the server. This is not very practical, as I often shut it down when I leave for a WE or for holidays.

Another option is to use a sub-directory of your maven project to be used as a crude repository for those packages.

Here are the steps:

  • In your pom.xml, add a new repository as follows (for a Windows platform):
<project>
  <repositories>
    <repository>
      <id>project-based-repository</id>
      <name>Project-specific jars</name>
      <url>file:///\${basedir}\libs</url>
    </repository>
  </repositories>
</project>

Under Unix, you get:

<project>
  <repositories>
    <repository>
      <id>project-based-repository</id>
      <name>Project-specific jars</name>
      <url>file:///${basedir}/libs</url>
    </repository>
  </repositories>
</project>

Watch your /s and \s depending on your platform!
${basedir} returns the root of your maven project

  • create a directory called libs at the root of your project
  • run maven on your project
  • supposing that you haven’t hacked your local repository to make it support the packages, you should get an error message such as (this one is for gienah-testing):

mvn install:install-file -DgroupId=org.gienah -DartifactId=testing -Dversion=E0.32 -Dpackaging=jar -Dfile=/path/to/file

  • this gives you the directory that you should create under libs: <groupId, split by periods>/<artifactId>/<version>. In our example, you get this: org/gienah/testing/E0.32.
  • download the tool, and copy the jar file in this newly created directory.
  • that should do it; run maven again and the build should pass.

Is it dirty? yes. Does is break maven’s recommendations? absolutely. But at least you’ve got something that works now

Thanks to Guillaume for figuring that one out.

Update (08/11/2010): better pom.xml sample; gave example for Unix systems

About Eric Lefevre-Ardant

Independent technical consultant.
This entry was posted in maven. Bookmark the permalink.

2 Responses to How to use Maven with no shared repository

  1. Robert Maldon says:

    I had a client last year that took the local directory-based repository one step further – the contents of the repository were checked into source control! They had enough resources to set up a proper Maven server and repository, but I guess CVS was there solution for most things – source control, maven repository and content management…

  2. Martin Burger says:

    Use <url>${project.baseUri}/libs/</url> instead.

Leave a Reply

Your email address will not be published.