Java Maven 预下载所有依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35944964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven pre-download all dependencies
提问by tsar2512
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.
我需要将我们的 maven build java 项目发布给远程 QA 团队。为此,我想下载所有依赖项,然后发送它们,这样他们就不需要下载它们。
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.
目前所有的依赖都在 pom.xml 文件中定义,我们使用 mvn install 或 mvn package 来构建项目。项目成员有的使用uber jars,有的使用jars+依赖来做执行。
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?
预先打包依赖 jar 文件的最简单方法是什么,这样就不需要从互联网上下载,并且不会过多地改变我们当前的构建过程?
采纳答案by Tunaki
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.
一个可能的解决方案是清除您的本地存储库,告诉 Maven 下载您项目的每个依赖项和插件依赖项,并制作一个 ZIP。
To purge your local repository, you can simply delete the folder {user.home}/.m2/repository
. Then, you can use the dependency:go-offline
goal:
要清除本地存储库,您只需删除文件夹{user.home}/.m2/repository
。然后,您可以使用dependency:go-offline
目标:
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.
然后,您可以简单地制作一个 ZIP{user.home}/.m2/repository
并将其发送给您的 Q/A 团队。他们需要将其解压缩到自己的内部{user.home}/.m2/repository
才能构建项目。
回答by Thanga
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
您的需求可以通过创建一个具有完全依赖关系的独立 jar 文件来完成。您可以将它移植到任何地方,请参阅https://stackoverflow.com/a/35359756/5678086
- Build a full dependency JAR file as said in the answer
- Copy the JAR to the destination machine you want
Run the below command from there
mvn install:install-file -Dfile=<path-to-file>
- 如答案中所述,构建完整的依赖 JAR 文件
- 将 JAR 复制到您想要的目标机器
从那里运行以下命令
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
这将在目标机器的 maven 存储库中安装依赖项。这是完全离线