Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: keeping dependent jars in project version control

Tags:

java

maven

So, I have a war project with several dependent jars that are not available in any repository. Up until recently, I'd been keeping them in src/main/webapp/WEB-INF/lib, and adding them to the pom with system scope.

I get that that's problematic, so I'm looking to clean up my build. I've semi-manually installed the jars into my .m2/repository via the install:install-file plugin. That's great for me, but what about the other people on my team? We're tiny, and setting up Nexus isn't really an option for us. I've resorted to adding comments to the pom.xml explaining how to run install:install-file for each jar.

I'm OK with the install:install-file solution, but I'd still like to include these artifacts in my project's version control, and not merely have them sprinkled about my filesystem.

Keeping them in src/main/webapp/WEB-INF/lib doesn't work, since that automatically adds them to the resulting war artifact (digression: if maven would simply go ahead and add them to the classpath here I'd be done, no need for install:install-file!)

Question: is there a sanctioned place in the maven directory layout where I can tuck these .jar files, just so that I can keep them as part of my project?

I do realize what's going on here- Maven is attempting to keep dependent jars outside of my build so that when other projects depend on my build, they can resolve the transitive dependencies. That's great for open-source projects that are going into the public maven repos, but I'd bet that the vast majority of people using Maven are working on "leaf" projects such as this, and it would be really handy to have a way to include jar files as part of the project without jumping through so many hoops.

like image 510
George Armhold Avatar asked Mar 14 '11 16:03

George Armhold


People also ask

Are Maven dependencies included in jar?

Apache Maven Shade Plugin provides the capability to package the artifact in an uber-jar, which consists of all dependencies required to run the project.

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.


1 Answers

If setting up Nexus or just a simple fileserver repo as suggested by Jan is really too much trouble, here are some other options:

  • Simply include the JARs and a script that'll install them all in a directory of your choosing in version control. No need for the Maven structure to sanction it.
  • Use your version control system as a host for the repository, either on a branch by itself in your main project or as a separate project. Let any backup, security, etc. you already have on version control apply to the repository without including the jars in the set of files that are actually being checked out and committed.
  • Include the jars in a folder that acts as a mini-repository that is checked out with the rest of the code. Have pom.xml point to that folder as a repository it uses. I'm not 100% sure this is possible, but it seems likely that it is.
like image 113
ColinD Avatar answered Nov 08 '22 11:11

ColinD