Search code examples
javaeclipsemavengradleeclipse-wtp

Java Flat Multi-Project with fast incremental compile and hot-code deploy - WTP? Eclipse? IDEA? Maven? Gradle?


We have a reasonably large interdependent multi-project code base currently using Java7 & Groovy built with Eclipse/WTP & Ant running Tomcat 7. Basically something what you would find in probably most Java Enterprise software development. We have tweaked our build process over the years but it is rather fragile within Eclipse, the Ant-only build works perfectly, though slowly:

  • workspace
    • jars
    • common
    • common-web (depends source)
    • web1 (depends common-web,common)
    • web2 (depends common-web,common)
    • web3 (depends common-web,common)
    • cli-app1 (depends common)
    • cli-app2 (depends common)

We used to build exclusively with Ant, creating common.jar, common-web.jar etc and copy into webN/WebContent/WEB-INF/lib. This worked but was slow and makes hot code replacement and incremental compile impossible (at least for changes in common*).

Now, we let Eclipse/WTP compile and assemble static resources. Common and common-web projects are added in Deployment Assembly as virtual jars, to prevent the time spent creating the jars. Ant still does some templating and copying of dynamic resources as well as copying all external jars into WEB-INF/lib (This is done by Ant as compared to Eclipse/Web App Libraries so we only have to maintain our list of jars in one place, build.xml, rather that having to maintain them separately for every project in Eclipse in addition to build.xml for production builds). After Ant is done, it automatically refreshes the WEB-INF/lib and WEB-INF/classes folders so the Eclipse/WTP is aware of the updated files.

For production deploys on the server we simply let Ant handle both the compiling and the assembling.

Our strategy of letting Eclipse/WTP deal with automatic incremental building and publishing to Tomcat for development, has reduced the Ant-only compile time of 2+ min to virtually instantaneous and allowing hot code replacement of common* classes. However this setup is very fragile as any file change on the file system without Eclipse' knowledge breaks the build. This also means than our project setup is complicated and thus needs to be checked in, which of course means it breaks frequently as colleagues accidentally check in local changes.

There has to be a better way to make flat multi module project work seamlessly in an IDE

I have looked into maven and gradle but both admit that when it comes to flat multi-module setups they just don't work (or do they?). Nesting is not possible due to multiple top level projects requiring the same sub-modules. Yes you can place the root pom.xml or gradle.settings in the folder above the projects, but that doesn't allow for seamless building/dependency management by Intellij or Eclipse as this folder isn't visible.

Unfortunately all tutorials and examples I have come across deal with hobby-project size setups. Never a true enterprise example with several ear/war and shared projects.

We are happy to change build tools or even IDE, should there be a tool chain that can actually deals with seamlessly compiling and assembling without having to leave the IDE and that's fast.

Basically, what we are after is "simply":

  • Automatic Dependency Management
  • Fast, incremental compile during development
  • Hot-Code replacement (WTP/JRebel Style)

SO, can you help?


Solution

  • In gradle you can have different settings.gradle in each of your module, e.g: in web1, add settings.gradle which have:

    include ':common'
    project(':common').projectDir = "../common" as File
    include ':common-web'
    project(':common-web').projectDir = "../common-web" as File
    

    then you can add dependencies in build.gradle like:

     compile project(':common')
     compile project(':common-web')
    

    gradle could help you do:

    • Automatic Dependency Management
    • incremental compile during development but it's much slower than ant in my experence
    • gradle have Jrebel plugin which can help the Hot-Code replacement.

    Gradle is very flexible and manageable compare to maven but it's slower and have more bugs compare to maven as it's much younger.