Can I have a Gradle multi project build that will generate more than one IntelliJ IDEA project?


(ariel) #1

Hello,

I’ve been trying to configure a multi project build but I haven’t been successful on getting everything to work the way I need it. Maybe you can help me.

My layout looks like this:

MyProduct
     |
     +--- AppProject
     |
       |
     |
       +---- AppModule1
     |
       \---- AppModule2
     |
     |
     \--- TestingProject
                 |
                 +---- TestModule1
                 \---- TestModule2

This is what I’d like to do:

  • By invoking gradle on MyProduct, I should be able to build everything and produce all the artifacts from all my modules.

  • I’m using IntelliJ IDEA and with the Gradle IDEA plugin I need to generate two separate projects: AppProject and TestingProject.

According to what I’ve read, you can only have one settings.gradle per multi project (which makes it the root project). However, based on what I’ve observed trying things out, the Gradle IDEA plugin will only generate a project file (.ipr) if the project is the root one, and the only way to make it the root one is by creating a settings.gradle file. That will mean having more than one settings.gradle

Is there a way I can have the Gradle IntelliJ IDEA pugin generate two project files (for AppProject and TestingProject) and all my product can be built invoking Gradle on MyProduct?

Thanks,

Ariel


(Peter Niederwieser) #2

Why do you need/want two IDEA projects? And don’t they have code dependencies?


(Tye Howard) #3

You can specify different settings files for your project using the ‘-c’ option. Granted you’d have to run your idea build twice (once with each settings file), but it would accomplish your stated objective: two .ipr files.

It’s also possible, though even uglier, to modify an init file which could handle the dual settings process for you.


(ariel) #4

@Peter They don’t have code dependencies. The AppProject generates a war that the TestingProject uses to run automated tests against it. The AppProject IntelliJ IDEA project generation is for the developers and the TestingProject one is targeted to the testers.

@Tye My problem with that is that the paths are relative to the root project. I have a dependency of TestModule1 on TestModule2 (dependsOn: “:TestModule2”) and my problem is that the dependency path changes depending on where my settings.gradle file is.


(Peter Niederwieser) #5

The AppProject IntelliJ IDEA project generation is for the developers and the TestingProject one is targeted to the testers.

In this case, I’d consider having two separate Gradle builds. Alternatively, you could declare and configure ‘GenerateIdeaWorkspace’/‘GenerateIdeaProject’/‘GenerateIdeaModule’ tasks yourself, instead of using the ‘idea’ plugin.