简体   繁体   中英

Gradle nested projects setup

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

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'

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM