3

Gradle multiproject structure

In RootProject, I have the build.gralde and settings.gradle. common,subProj1 and subProj2 are subprojects in settings.gradle

intermediateDir IS NOT a subproject! It is used only for grouping the subProj1, subProj2 since they are related.

Everytime I run "gradle eclipse" in the root directory, I get .classpath and .project files also in the intermediateDir, which I shouldn't since this is not a sub project! So basically intermediateDir is considered a sub project for some tasks, even if not in settings.gradle. Any quick way around this?

1 Answer 1

8

The way you've written settings.gradle, the intermediate directory is a subproject. Often this is desirable, as it allows you to easily configure and execute its child projects in one go, even if the intermediate project doesn't have any files or tasks of its own.

To get rid of unwanted behavior for an intermediate project, either make sure to not apply that behavior (e.g. apply plugin: "eclipse") to that project (probably you are applying it to allprojects right now), or change settings.gradle to not create an intermediate project. For example:

include "common"   
// name it any way you like, but not 
// "intermediateDir:subProj1", i.e. no ":"
include "subProj1" 
include "subProj2"

project(":subProj1").projectDir = file("intermediateDir/subProj1")
project(":subProj2").projectDir = file("intermediateDir/subProj2")
Sign up to request clarification or add additional context in comments.

2 Comments

You Sir are God. I knew it was going to be you who answers, next time I will ask by name, just joking, but yes, nice tool. The option of not applying the eclipse plugin, probably works, but I want to apply common plugins in the "subprojects{...}" in the root build.gradle.
This should really be included in the official docs. I understand it's more desirable to include the intermediate dir, but it's such a gotcha. Thank you so much for this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.