1

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

kerelape
  • 114
  • 8

2 Answers2

1

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'
PrasadU
  • 2,154
  • 1
  • 9
  • 10
0

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")
kerelape
  • 114
  • 8
  • Say root(App) had another common module within it (at the same level as 'frontend'/'backend') - would it be possible to add it as a dependency within 'frontend' or 'backend'? – nauf Mar 13 '23 at 21:52