Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij multi-module maven project, update in one of the submodules is not propagated to war

I'm using Intellij Idea 12 and have a multi module maven project.

To make it simple let's assume that I have:

  • Module A - compiled to JAR
  • Module B - depending on module A and also compiled to JAR
  • Module C - depending on module B, but compiled to WAR

I know Intellij has it's own build mechanism for maven projects so when I build a WAR for the first time and deploy it to Tomcat generally all works as it should. The problem start when you need to make changes in one of the sub modules, for example Module A and rebuild the War (rebuild Module C)

Intellij as it seems uses the old Module A jar that was previously build and ignores any changes I made in Module A when making/building Module C.

The only way I found to solve this is to run a Maven build on Module A and B and initiallly build the WAR with Maven and deploy it as external source.

The problem is that I have 10 WARs I want to deploy and more then 20 sub modules that compiled to jars. It doesn't make sense to rebuild all wars when I'm only want to see the changes I made in one of sub modules that affects one WAR. And sure doesn't make sense to build them externally with command line while paying for Intellij Ultimate license (so I can work with Application servers)

Now comparing this behavior to other IDE 1. Netbeans works with maven projects naturally via Maven and all builds/deployments and such are done with Maven and not by some internal mechanism. 2. Eclipse does the same with it's internal mechanism but all JARs are updated when WAR project are rebuild. (Or some other magic that works)

Is there a way work differently with IDEA or there isn't ?

like image 646
Tal G. Avatar asked Apr 24 '13 17:04

Tal G.


1 Answers

Eventually I found a hybrid solution for this: Things to be done before Tomcat is run:

  1. Clean all
  2. Build, package and register (in repository) all projects that should become JAR
  3. Compile only (Don't build) WAR projects
  4. Build WAR artifacts with Intellij (This is needed for hot swap availability)

This is how I start Tomcat.

Detailed information:

  1. Create 3 Maven run configurations

    1.1 Clean all projects Maven Clean for all Projects 1.2 Build all projects with JAR artifacts. You need to manually include all your projects with the '-pl' maven option. Optionally you can run "Maven clean" before launch of this configuration (look at screenshot) Build Jars 1.3 Compile all Projects with WAR artifacts - No packaging with MavenCompile WARs

  2. Create Tomcat configuration to Build War artifacts and include other configurations to run before Launch enter image description here

Now when Tomcat is run it is possible to hotswap code changes (if JVM allows) or simply restart server to include all your new code/changes. The draw back of this is somewhat longer start time of Tomcat. That's something we are willing to live with..... For now

like image 130
Tal G. Avatar answered Oct 09 '22 16:10

Tal G.