Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having difficulty setting up Gradle multiproject build for existing repository layout

Tags:

gradle

I'm trying to craft a Gradle multiproject build for a situation in which my project layout is already dictated to me. I have something like this:

-->Shared\
---->SharedComponent1\
------>build.gradle
------>src\
...
---->SharedComponent2\
------>build.gradle
...
-->Product1\
---->ProductComponent1\
------>build.gradle
---->ProductComponent2\
------>build.gradle
...
---->build\
------>settings.gradle

My settings.gradle looks like this:

rootProject.name = 'Product1'
rootProject.projectDir = new File( "${ProjectsRoot}" )

include 'Shared:SharedComponent1'
include 'Shared:SharedComponent2'
include 'Product1:ProductComponent1'
include 'Product1:ProductComponent2'

When I run Gradle in the build folder like this:

gradle -PProjectsRoot=c:\my\project\root\dir projects

I get:

:projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'build'
No sub-projects

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :tasks

BUILD SUCCESSFUL

i.e. it doesn't find the projects I'm trying to build. Is what I'm trying to do possible with Gradle's multiproject support? Or am I barking up the wrong tree?

like image 460
Andy McKibbin Avatar asked Feb 06 '13 12:02

Andy McKibbin


People also ask

Can we have multiple build Gradle?

Creating a multi-project buildA multi-project build in Gradle consists of one root project, and one or more subprojects. This is the recommended project structure for starting any Gradle project.

Why is my Gradle build so slow?

This happens due to the fact that the module needs to be built from the scratch every time. Enable gradle Offline Work from Preferences-> Build, Execution, Deployment-> Build Tools-> Gradle. This will not allow the gradle to access the network during build and force it to resolve the dependencies from the cache itself.


1 Answers

For completeness, the settings.gradle that solved my specific example above is as follows:

rootProject.name = 'Product1'

def projectTreeRootDir = new File( "${ProjectsRoot}" )

// Shared components

def sharedRootDir = new File( projectTreeRootDir, 'Shared' )

include ':SharedComponent1'
project( ':SharedComponent1' ).projectDir = new File( sharedRootDir, 'SharedComponent1' )

include ':SharedComponent2'
project( ':SharedComponent2' ).projectDir = new File( sharedRootDir, 'SharedComponent2' )

// Product components

includeFlat 'ProductComponent1', 'ProductComponent2'

Clearly this doesn't scale to large numbers of subprojects and it could be done significantly better using the hints provided by Peter above.

like image 78
Andy McKibbin Avatar answered Oct 30 '22 12:10

Andy McKibbin