在特定执行阶段忽略Maven依赖关系 [英] ignore maven dependency during specific execution phase

查看:112
本文介绍了在特定执行阶段忽略Maven依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(自定义的)嵌入式码头发射器,在迁移到Maven之前,我曾用它来开发/测试我的Web应用程序.

I have a (custom) embedded jetty launcher which I had been using to develop/test my web application (before moving to maven).

我能够欺骗m2eclipse来将Maven管理的依赖项放入战争文件库中,以将war文件放到启动程序类路径上(从eclipse运行时).为此,我为同一工件创建了两个依赖项:一个是"war"类型,另一个是"jar"类型("jar"依赖项使m2eclipse可以执行我想要的操作).

I am able to trick m2eclipse into putting the maven managed dependencies to libraries for the war file onto the launcher classpath (when run from eclipse). I did this by creating two dependencies for the same artifact: one of the type "war" and one the type "jar" ("jar" dependence tricks m2eclipse into doing what I want).

但是,当启动器的maven-assembly-plugin无法找到战争项目的jar时,它就会失败.

However the maven-assembly-plugin for the launcher fails when it cannot find the jar for the war project.

问::运行程序包目标时,我可以告诉maven忽略jar依赖吗?

Q: Can I tell maven to ignore the jar dependency when running the package goal?

更详细的背景信息: 在转到Maven之前,我有一个webapp.war项目和一个码头发射器项目.我有一个Eclipse项目依赖项,因此启动器在运行时具有所有战争依赖​​项.一切都耗尽了测试变更所需的能力(无需重新构建warfile).

more detailed background: I have a webapp.war project and a jetty-launcher project, before moving to maven; I had an eclipse project dependency so that the launcher had all the war dependencies at runtime. Everything ran right out of the ide (with no re-build of the warfile) needed to test changes.

转移到Maven后,此方法不明智,因为m2eclipse知道不包括jar依赖的库(因为它们在战争范围内).

After moving to maven, this approach was outsmarted since m2eclipse knows not to include the libraries that the jar depends on (since they are war scoped).

推荐答案

我通过使用单独的.m2/settings-eclipse.xml(用于eclipse)解决了此问题,在该示例中,我重写了默认的依赖类型.所以在我的启动器POM中,我有:

I got around this by using a seperate .m2/settings-eclipse.xml (for eclipse) where I over-ride the default type of dependency. so in my launcher POM, I have:

<dependency>
  <groupId>com.myco</groupId>
  <artifactId>my-server</artifactId>
  <version>${project.version}</version>

  <!-- here we want eclipse to see "jar" but command line to see "war" -->
  <type>${jetty.launcher.workaround}</type>
</dependency>

我仍然想知道是否有直接方法可以解决原始问题.

I still would like to know if there is a direct way to approach the original problem.

这篇关于在特定执行阶段忽略Maven依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆