Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice wrt. `mvn install`, multi-module projects, and running one submodule

Tags:

maven

I tend to avoid using mvn install in my multi-module projects because I feel like I then don't know which exact version of a submodule is then used when building / launching other submodules (particularly when switching between branches very often).
I tend to use mvn package a lot and then mvn verify.

I'm now facing the issue in 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)

like image 765
Thomas Broyer Avatar asked May 21 '12 13:05

Thomas Broyer


2 Answers

The mvn install is common in particular in relationship with multi-module builds, cause it will give you the chance to run a single module from your multi-module build.

This can be achieved by using:

mvn -pl submodule LifeCycle
like image 50
khmarbaise Avatar answered Oct 01 '22 20:10

khmarbaise


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).

like image 28
Thomas Broyer Avatar answered Oct 01 '22 21:10

Thomas Broyer