最佳做法. `mvn install`,多模块项目,并运行一个子模块 [英] Best practice wrt. `mvn install`, multi-module projects, and running one submodule

查看:189
本文介绍了最佳做法. `mvn install`,多模块项目,并运行一个子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于避免在多模块项目中使用mvn install,因为我感觉那时我不知道在构建/启动其他子模块时会使用哪个确切版本的子模块(尤其是当经常在分支之间切换时) ).
我倾向于先使用mvn package,然后再使用mvn verify.

我现在在一个FOSS项目(一个Maven原型)中正面临这个问题. ),我想使用Maven的最佳实践.
这是一个带有webapp子模块的多模块项目,具体取决于其他模块,而让我担心的是易于开发mvn jetty:run(或jetty:start).

当前,我定义了2个配置文件:

  1. prod是默认的,它声明对其他子模块的依赖关系;
  2. 另一方面,
  3. dev 依赖于其他模块,并通过将其他模块的输出目录添加为extraClasspathresourcesAsCSV来配置jetty-maven-plugin. > 这样,我可以先mvn package然后cd webapp && mvn jetty:start -Pdev并快速进行迭代,重新加载Webapp,而无需停止服务器.

AFAICT,extraClasspath是为该确切目的而添加的( JETTY-1206 ) .
我已经指出了tomcat7-maven-plugin,它可以在使用Maven 3时解析反应堆中的模块(我提出了一个问题将其引入Jetty:解决方案

我刚刚找到了一种解决方法(事后看来似乎很合逻辑):a FOSS project (a Maven archetype moreover) where I'd like to use Maven's best practices.
It's a multi-module project with a webapp submodule depending on the other modules, and what worries me is the ease of development along with mvn jetty:run (or jetty:start).

Currently, I defined 2 profiles:

  1. prod, the default one, declares dependencies on the other submodules;
  2. dev on the other hand does not depend on the other modules, and configures the jetty-maven-plugin by adding the other modules' output directories as extraClasspath and resourcesAsCSV.
    That way, I can mvn package once and then cd webapp && mvn jetty:start -Pdev and quickly iterate, reloading the webapp without the need to even stop the server.

AFAICT, extraClasspath was added for that exact purpose (JETTY-1206).
I've been pointed at the tomcat7-maven-plugin which can resolve modules from the reactor build when using Maven 3 (and I raised an issue to bring the same to Jetty: JETTY-1517), but that hardly solve my

If I hadn't removed the dependency on the other submodules from in dev profile, I'd have had to do an mvn install first so that validating the POM doesn't fail, even if jetty:start doesn't use those dependencies afterwards.

So here's my question: is mvn install really that common? or my approach of putting the intra-reactor dependencies only in the prod profile OK?

(note that I have the exact same problem with the gwt-maven-plugin, so please don't tell me to simply switch to Tomcat; that wouldn't even work actually, details here)

解决方案

I just found a workaround (which seems logical as an afterthought): https://jira.codehaus.org/browse/JETTY-1517?focusedCommentId=306630&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-306630

In brief: skip the plugin by default in the parent module then re-enable it where needed.

This however only works if the plugin can be skipped (i.e. has a skip configuration) and is only used in one specific submodule, and it has to be selectively done for each plugin you need/want to run that way (in my case, jetty:run and gwt:run).

这篇关于最佳做法. `mvn install`,多模块项目,并运行一个子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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