We're very pleased that you want to get in touch with us. Please fill in the form below:



or   Close this form  
Some content

Peter Pilgrim :: Java Champion :: Digital Developer Architect

I design Java EE and Scala software solutions for the blue-chip clients and private sector

Hey all! Thanks for visiting. I provide fringe benefits to interested readers: checkout consultancy, training or mentorship Please make enquiries by email or call +44 (0)7397 067 658.

Due to the Off-Payroll Working plan for the UK government, I am enforcing stricter measures on contracts. All potential public sector GOV.UK contracts engagements must be approved by QDOS and/or SJD Accounting. Please enquire for further information.

Java EE 7 Handbook: Gradle Multi-Modules Puzzle

02 August 2013 4 comments

2 minutes

396

Yesterday, I converted Gradle build code base for my upcoming Java EE 7 Developer Handbook book from invidual modules to multi-module. I thought I had this structure down, but I surprisingly I am stuck.

Here is my book’s code structure in folder hierarchy:

javaee7handbook
javaee7handbook/build.gradle
javaee7handbook/settings.gradle
javaee7handbook/ch01
javaee7handbook/ch01/foo/build.gradle
javaee7handbook/ch02
javaee7handbook/ch02/bar/build.gradle
javaee7handbook/ch03
javaee7handbook/ch03/donkey/build.gradle
javaee7handbook/ch04/jpa-simple
javaee7handbook/ch04/jpa-simple/build.gradle

This structure runs for 14 chapters including appendices.
So I have master hierarchy defined in settings.gradle and it looks like this:

include 'ch01/foo', 'ch02/bar', 'ch03/donkey', 'ch04/jpa-simple', ...

With Gradle multi-module build, readers can execute gradle build from the root javaee7handbook folder and everything will build and run to test to completely. This is great for readers of my book, they can get started very quickly and I am sure they love Gradle.

My problem is that want the novice users to go any sub folder / multi-module and execute either gradle idea or gradle eclipse and just see a single project view.

Whenever I open now a sub module say javaee7handbook/ch04/jpa-simple/build.gradle I find that IntelliJ replicates the whole structure inside the sub module!!!

javaee7handbook/ch04/jpa-simple/
javaee7handbook/ch04/jpa-simple/ch01
javaee7handbook/ch04/jpa-simple/ch01/build.gradle
javaee7handbook/ch04/jpa-simple/ch02
javaee7handbook/ch04/jpa-simple/ch02/build.gradle
javaee7handbook/ch04/jpa-simple/ch03
javaee7handbook/ch04/jpa-simple/ch03/build.gradle
javaee7handbook/ch04/jpa-simple/ch04
javaee7handbook/ch04/jpa-simple/ch04/build.gradle

The upper folders replicate into the sub module and IDEA gets totally confused. The JetGradle runs for a long time. This is not acceptable for people new to Java EE 7 and expect a seamless experience and yet Gradle is new way to build software. Android is already there and so is JavaFX 8. So what to do?

In fact, running gradle idea generates a javaee7handbook.iml and not the jpa-simple.ipr that I expected file I saw when the Gradle project was not multimodule. I just my readers to see the project jpa-simple and not bring in the rest of code related to other chapters. Can you help me figure out quickly how to solve this?

+PP+

4 Comments

  1. That’s just not the way it works unfortunately.

    You have to run idea/eclipse from the root, as a view of the whole project is needed.

    IDEA has no partial import feature, it’s all or nothing.

    In Eclipse, you can bring just the modules you want into your workspace.

    If you need more sophistication, you have to script something up in settings.gradle to project a dynamic view of the project. This is not something that is entirely trivial though and requires a bit of planning.

    Comment by Luke Daley — 02 August 2013 @ 10:55 am

  2. Thanks very much Luke for your time and input. It’s pity that partial views do not work currently in IDEA with Gradle. This explains why IDEA was struggling and pulling in the entire project in a sub module.

    Therefore for ease of use of my readers, I must revert and remove the multi-module nature of the distribution.

    Comment by Peter Pilgrim — 02 August 2013 @ 11:48 am

  3. Considering its a java ee book does it matter if the build is maven or gradle. I’m sure multi module builds would work with maven. That said, picking up gradle has been on my todo list for awhile now, so if you are introducing that in your book as well, it might be worthwhile for me as a reader

    Comment by Suneet Kamath — 04 August 2013 @ 11:12 am

  4. Suneet you will then enjoy my book, because it uses Gradle exclusively. There is brief introduction to Gradle in chapter 2 with CDI, then it assumes you know. The entire source code distribution uses Gradle, even though it is not perfect and still has some issues with Maven, however other larger projects such as Android, Spring Framework and JavaFX have migrated to Gradle.

    Comment by Peter Pilgrim — 04 August 2013 @ 5:58 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Contents of this blog entry are under copyright © 2017 by Peter Pilgrim and associates. For enquiries after republishing, please contact us for permission. All requests for syndicated content will be ignored /dev/null, consider yourself warned!

I help to design, create and build JVM components and services that are behind popular e-commerce websites.

My Blurb

Please get in touch , directly, to establish hire availability, contract & consulting opportunities.

Speaking at Your Conference

Contact by invitation

What Peter Does

Contact