Gradle nested projects setup

1.4k views Asked by At

How do I set up such a project structure where I have the root project called "app", "frontend" and "backend" project inside and a count of library projects inside each. Then run a build task that would give me one backend jar and a swing (for example) jar application.

Like this:

  • root (App)
    • frontend
      • library
      • main
    • backend
      • library
      • main

then run: gradle build and have build/.../frontend.jar and build/.../backend.jar

I did try using include inside settings.gradle but that doesn't seem to work (at least gradle projects and intellij idea do not recognise the projects inside frontend and backend). I had:

root/settings.gradle with: include 'frontend', 'backend' root/backend/settings.gradle with: include 'library', 'main' and the same for frontend

2

There are 2 answers

1
kerelape On BEST ANSWER

In modern Gradle it's possible to includeBuild, which solves the problem perfeclty:

// root/settings.gradle.kts
rootProject.name = "root"

includeBuild("backend")
includeBuild("frontend")
// root/backend/settings.gradle.kts and root/frontend/settings.gradle.kts

include(":library")
include(":main")
0
PrasadU On

There are multiple ways. one way at the root settings.gradle (gradle v7.1)

rootProject.name = 'test-prj-tree'
include 'backend'
include 'frontend'
include 'library'
include 'backend:library'
findProject(':backend:library')?.name = 'backend-lib'
include 'backend:main'
findProject(':backend:main')?.name = 'backend-main'
include 'frontend:library'
findProject(':frontend:library')?.name = 'frontend-lib'
include 'frontend:main'
findProject(':frontend:main')?.name = 'frontend-main'