简体   繁体   English

如何复制多模块项目的依赖项?

[英]How to copy dependencies of a multi module project?

I have a project that depends on a different project-module in my workspace. 我有一个依赖于工作区中不同项目模块的项目。 I'm trying to copy all dependencies (including the module) to a lib folder for creating an executable jar that has no packaged all jars inside itself. 我试图将所有依赖项(包括模块)复制到lib文件夹中,以创建一个可执行jar,而该jar中没有打包所有jar。

But maven-dependency-plugin keeps complaining that it could not copy the module classes to the target folder of my project. 但是, maven-dependency-plugin一直抱怨无法将模块类复制到项目的目标文件夹中。 What might be wrong? 可能是什么问题?

my.groupt my-module 1.0 my.groupt我的模块1.0

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
       <execution>
          <id>copy-dependencies</id>
          <phase>package</phase>
          <goals>
             <goal>copy-dependencies</goal>
          </goals>
          <configuration>
             <outputDirectory>${project.build.directory}/lib</outputDirectory>
          </configuration>
       </execution>
    </executions>
 </plugin>

Result: 结果:

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:copy-dependencies (copy-dependencies) on project my-project: Error copying artifact from C:\\workspace\\my-module\\target\\classes to C:\\workspace\\my-project\\target\\lib\\classes: (Access denied) 无法在项目my-project上执行目标org.apache.maven.plugins:maven-dependency-plugin:2.1:copy-dependencies(副本依赖项):从C:\\ workspace \\ my-module \\ target \\ classes复制工件时出错到C:\\ workspace \\ my-project \\ target \\ lib \\ classes:(拒绝访问)

The reason for your failure is workspace resolution in eclipse. 失败的原因是Eclipse中的工作区解析。 Eclipse m2e injects itself into the artifact resolution of maven. Eclipse m2e将自身注入到maven的工件解析中。

So when your my-project tries to get all dependencies, the artifact resolver returns not the jar file (which does not yet exist), but the classes folder of your dependent project. 因此,当您的my-project尝试获取所有依赖项时,工件解析器将不返回jar文件(尚不存在),而是返回依赖项目的classes文件夹。

If you try to build your project using "run as -> maven install", it should work. 如果您尝试使用“运行方式-> maven install”来构建项目,则它应该可以工作。

So this is a scenario that you cannot comfortably resolve in workspace. 因此,这是您无法在工作区中轻松解决的情况。 Either turn of workspace resolution for my-project, disable the dependency plugin inside your eclipse (lifecycle bindings) or use a different plugin like assembly to copy your depdencies (which is cleaner, btw.). 为我的项目打开工作空间分辨率,禁用eclipse中的依赖项插件(生命周期绑定),或使用其他插件(如Assembly)来复制您的依赖关系(顺便说一句)。 Note however, that the latter will also only work if maven is called manually. 但是请注意,后者仅在手动调用maven时也有效。

You are probably looking for the Maven Shade plugin. 您可能正在寻找Maven Shade插件。

It is much more flexible but be warned - any module built through Maven Shade makes automatic tracing of dependencies very difficult. 它要灵活得多,但要注意-通过Maven Shade构建的任何模块都使自动跟踪依赖关系变得非常困难。 Try not to make your shaded result the primary outcome of the build process. 尽量不要使阴影结果成为构建过程的主要结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何发布具有未发布依赖项的多模块项目 - How to release a multi-module project with non released dependencies 对多模块Maven项目的循环依赖 - Cyclic dependencies on multi-module maven project 无法解决Maven多模块项目中的依赖关系 - failed to resolve dependencies in maven multi module project 在多模块 maven 项目中部署具有依赖项的子模块 - Deploy submodules with dependencies in multi module maven project 无法解决 maven 多模块项目的依赖关系 - Could not resolve dependencies for maven multi module project 带有maven的多模块IntelliJ项目 - 如何将依赖项从一个模块添加到另一个模块? - Multi-module IntelliJ project with maven - How to add dependencies from one module to another? Gradle多模块项目无法找到模块依赖项 - Gradle multi module project cannot find module dependencies 具有同级项目依赖项的多模块Maven Spring启动项目 - Multi module Maven Spring boot Project with sibling project dependencies 如何在 spring-boot 多模块 Java 11 项目中添加 Spark 依赖 - How to add Spark dependencies in spring-boot multi module Java 11 project 在多模块Maven项目中临时解决依赖项 - Resolving dependencies ad-hoc in multi-module maven project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM