24

I need to release our Maven build Java project to an remote QA team. For this I would like to download all the dependencies, and send them so they do not need to download them.

Currently all dependencies are defined in the pom.xml file, and we use either mvn install or mvn package to build the project. Some of the project members use uber jars, others use jars + dependencies to do execution.

What would be the easiest way to pre-package the dependent jar files so that there is no download from the internet, and does not change our current build process too much?

Lii
  • 9,906
  • 6
  • 53
  • 73
tsar2512
  • 2,282
  • 2
  • 28
  • 46
  • 1
    Create a local maven repository such as artifactory in your network. That way the dependencies get cached in your local network. – f1sh Mar 11 '16 at 16:15
  • Can you explain this process in details? How would I package this local maven repository and send it to a remote team? – tsar2512 Mar 11 '16 at 16:16
  • No, a repository in a local network just prevents each team member to download all the dependencies from the internet. Instead, they will be cached in the repository and can be downloaded from there. Right now I don't understand why you want to send them any dependencies. The whole purpose of maven dependencies is that you DONT have to package and send them, instead you only need to reference them in the pom.xml – f1sh Mar 11 '16 at 16:23
  • 1
    Or, you could go offline with `mvn dependency:go-offline` and make a ZIP of your local repo. – Tunaki Mar 11 '16 at 16:24
  • I understand, this is a requirement from the QA team. I have explained that maven specifies the exact dependency. However, this is how they want it.. so trying to figure out a way. – tsar2512 Mar 11 '16 at 16:25
  • ant allows the developer to specify a lib directory, and you can install using the jars in that. Does maven allow something similar? – tsar2512 Mar 11 '16 at 16:27
  • @tunaki thanks for the suggestion. Could you explain your proposal in detail in an answer? – tsar2512 Mar 11 '16 at 16:28
  • 4
    Your build system is inefficient. You should produce a single release artefact (maybe many files), and promote that between environments. Right now you really have no idea that the testers have tested the same thing you built -- anything could be in those poms or dependencies. – Software Engineer Mar 11 '16 at 16:42
  • As @EngineerDollery already stated you are using the build system wrong...you should use the Maven way like making a correct release of your project deploy them to a repository manager and offer those artifacts to your QA team and after a successful test you can stage them to the next state... – khmarbaise Mar 13 '16 at 19:10

3 Answers3

39

A possible solution would be to purge your local repository, tell Maven to download every dependencies and plugin dependencies of your project and make a ZIP of that.

To purge your local repository, you can simply delete the folder {user.home}/.m2/repository. Then, you can use the dependency:go-offline goal:

Goal that resolves all project dependencies, including plugins and reports and their dependencies.

mvn dependency:go-offline

This will download everything that your project depends on and will make sure that on a later build, nothing will be downloaded.

Then, you can simply make a ZIP of {user.home}/.m2/repository and send that to your Q/A team. They will need to unzip it inside their own {user.home}/.m2/repository to be able to build the project.

Tunaki
  • 116,530
  • 39
  • 281
  • 370
4

Offline Package deploy

Your requirement can be accomplished by creating a stand alone jar file with full dependencies. You can port it anywhere please refer https://stackoverflow.com/a/35359756/5678086

  1. Build a full dependency JAR file as said in the answer
  2. Copy the JAR to the destination machine you want
  3. Run the below command from there

    mvn install:install-file -Dfile=<path-to-file>
    

This will install the dependecies in the maven repository of the destination machine. This is fully offline

Community
  • 1
  • 1
Thanga
  • 6,775
  • 3
  • 14
  • 34
0

Theoretically if you know which maven commands you'll use (package, install, etc.) you could clear out your ~/.m2/repository folder, run those commands once on somebody's dev box, then distribute the repository folder. You can run maven -o install etc. to have it not give annoying warnings. This might be a slightly smaller distro than the go-offline answer.

rogerdpack
  • 50,731
  • 31
  • 212
  • 332