1

I need to configure maven to download the dependencies to a directory within my project so that I can copy my project to another PC without internet access. I have found the -o option and the "dependency: copy-dependencies" plugin, but nobody explains how to consume those dependencies later. What would be the way to download the dependencies and then consume it on a PC without an Internet connection?

cstff
  • 83
  • 9
  • have you looked at https://stackoverflow.com/questions/35944964/maven-pre-download-all-dependencies ? – radai Sep 21 '19 at 06:22

2 Answers2

2

Maven caches downloaded dependencies (and plugins -- just having the project's dependencies won't necessarily be enough depending on the pom structure) in ~/.m2/repository. If you build your project, then clone the ~/.m2/repository directory as well as your project to another machine, you should be able to build in offline mode with all dependencies available to use.

Joe
  • 527
  • 4
  • 13
  • Thank @Joe but, this folder could grow as you work on several projects or with different versions of the libraries. If I wanted to pass my project to another programmer then I should manually choose which dependencies to copy or copy the entire contents of the folder. The dependency: copy-dependencies plugin by default copies the dependencies to the target folder of the project. What happens is that I am new using maven and I can't find how to consume those dependencies on the PC without internet. – cstff Sep 20 '19 at 21:06
  • yeah, you could delete/move the cache directory out of the way and recreate it by building on the connected PC, then move the slimmed down copy over to the unconnected PC, but agree it's not ideal. – Joe Sep 23 '19 at 17:57
0

The dependency:copy-dependencies is pretty useless for the task you try to solve. You usually need much more to successfully build a project.

You can use a dedicated local repository for you project (this can be set on the command line), so that you can copy that (without the content coming from all the other projects).

But if you are in a company, the recommended way is to set up a Nexus/Artifactory server that manages your dependencies. Then you don't need internet access to build, but just access to that server.

J Fabian Meier
  • 26,766
  • 8
  • 52
  • 98