Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundling a non-open-source dependency with Maven

Suppose I have two Java projects in Maven / Eclipse:

  • An open source application hosted in GitHub
  • A small private library containing utility functions which is not open source (but which I do have the rights to modify, build, and redistribute in compiled form e.g. as a .jar file)

I'd like to make it possible for others to build, modify and run the application (and contribute back to the open source project if they like!), but this means that they will also need the library as a dependency.

I'd like to keep things simple, so that builds are easy both for myself and users of the application.

What's the most practical way to make this work?

like image 403
mikera Avatar asked Jun 27 '12 11:06

mikera


3 Answers

Provide your own Maven repository on GitHub to distribute the closed source library which you are allowed to redistribute and reference it from your project (pom.xml).

http://cemerick.com/2010/08/24/hosting-maven-repos-on-github gives a nice introduction on how to set up a repository on GitHub. You should be aware of the caveats of such a micro repository also mentioned in that post.

like image 96
stefanglase Avatar answered Sep 29 '22 23:09

stefanglase


A really simple solution would be to place your private library into your project (e.g. <project>/lib/library-1.0.jar) and include it as system dependency. You can include it in your pom like.

<dependencies>
    <dependency>
      <groupId>my.private</groupId>
      <artifactId>library</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/library-1.0.jar</systemPath>
    </dependency>
  </dependencies>

Caution: A system dependency is not transitiv!

From the documentation

This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

like image 45
FrVaBe Avatar answered Sep 29 '22 23:09

FrVaBe


When working with Maven it is recommended to use a Maven Repository Manager such as Nexus and configure your settings file as described here:

https://help.sonatype.com/display/NXRM3/Maven+Repositories#MavenRepositories-ConfiguringApacheMaven

In your situation this has the additional benefit that you could use the Maven Repository Manager to host any private artifacts.

like image 24
Puce Avatar answered Sep 29 '22 23:09

Puce