Home > Mobile >  Gradle nested projects setup
Gradle nested projects setup

Time:04-05

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

CodePudding user response:

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'
  • Related