Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - Recursive subprojects

Tags:

Assume I wanted to use Gradle with a project structure such as:

RootProject \-- SubProjectA     \-- SubProjectAA     \-- SubProjectAB 

How I would I achieve this?

What I tried is pretty straightforward. I've created all directories, with a structure described above:

RootProject \-- SubProjectA     \-- SubProjectAA         \-- build.gradle     \-- SubProjectAB         \-- build.gradle     \-- build.gradle     \-- settings.gradle \-- build.gradle \-- settings.gradle 

RootProject/settings.gradle:

include "SubProjectA" 

RootProject/SubProjectA/settings.gradle:

include "SubProjectAA", "SubProjectAB" 

There are two things I tried. First, I tried importing the project in Eclipse - which didn't detect SubProjectAA nor SubProjectAB. Stunned, I ran gradle projects in RootProject and got this output:

------------------------------------------------------------ Root project ------------------------------------------------------------  Root project 'RootProject' \--- Project ':SubProjectA' 

Still, thinking I made a mistake, I tried running the same command in SubProjectA, and got:

------------------------------------------------------------ Root project ------------------------------------------------------------  Root project 'RootProject' \--- Project ':SubProjectAA' \--- Project ':SubProjectAB' 

I assume that resolving subprojects doesn't go recursively. Is there any workaround for this?

Every example is masked with sample names, sorry if I made any mistake.

Thanks!

like image 401
Matija Folnovic Avatar asked Sep 07 '13 18:09

Matija Folnovic


People also ask

What is a subproject producer in Gradle?

The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency.

What is a real life example of a Gradle project?

Real life examples. Gradle’s multi-project features are driven by real life use cases. One good example consists of two web application projects and a parent project that creates a distribution including the two web applications. [1] For the example we use only one build script and do cross project configuration.

What is a project dependency in Gradle?

A project dependency is a special form of an execution dependency. It causes the other project to be built first and adds the jar with the classes of the other project to the classpath. It also adds the dependencies of the other project to the classpath. You can trigger a gradle :api:compile.

Is it possible to change the project path in Gradle?

In addition, changing a project path requires you to change all places where the project dependency is used, but it is easy to miss one or more occurrences (because you have to rely on search and replace). Since Gradle 7, Gradle offers an experimental type-safe API for project dependencies.


1 Answers

You can only have one settings.gradle. Typically it would contain something like:

include "SubProjectA:SubProjectAA" include "SubProjectA:SubProjectAB" 

More information can be found in the "multi-project builds" chapter of the Gradle User Guide.

like image 75
Peter Niederwieser Avatar answered Nov 08 '22 05:11

Peter Niederwieser