[JAVA] Configure a multi-project with subdirectories in Gradle


This is a way to build a Gradle multi-project when you have a hierarchical structure with subdirectories. I referred to the article below. https://qiita.com/shiena/items/371fe817c8fb6be2bb1e


Code sample

I have uploaded the sample code to Github. https://github.com/tYoshiyuki/java-gradle-multiproject

Configuration example

The following configuration is assumed.

Project name Description
master Root project
common/main-lib Common library part 1
common/sub-lib Common library part 2
app/api Individual application sample
app/web Individual application sample
app/batch Individual application sample

Setting method

Set the Gradle settings for the entire project in the root folder. In includeFlat, specify the common and app folders in the same hierarchy. After that, specify the project of the subdirectory with include.


rootProject.name = 'root'
includeFlat 'common', 'app'
include 'common:main-lib', 'common:sub-lib'
include 'app:web', 'app:api', 'app:batch'

Browse the common library from the project of each application.


project('app:web') {
    dependencies {
        implementation project(':common:main-lib')
        implementation project(':common:sub-lib')

If you import it as a Gradle project from IntelliJ IDEA, you can see that each project is recognized.


Recommended Posts

Configure a multi-project with subdirectories in Gradle
Add a project in any folder with Gradle
Java multi-project creation with Gradle
Spring Boot 2 multi-project in Gradle
Generate a single executable jar with dependent libraries in Gradle 4.9
Build a Java project with Gradle
Make multi-project executable JAR in Gradle
Split a string with ". (Dot)" in Java
Read a string in a PDF file with Java
Multi-project with Keycloak
Create a CSR with extended information in Java
Static code analysis with Checkstyle in Java + Gradle
Java tips-Create a Spring Boot project in Gradle
I wanted to gradle spring boot with multi-project
[Note] Build a Python3 environment with Docker in EC2
[How to insert a video in haml with Rails]
Quickly implement a singleton with an enum in Java
Check coverage with Codecov in Java + Gradle + Wercker configuration
Use Coveralls with GitHub Actions in a Ruby repository
Use ProGuard with Gradle
Install Gradle with ubuntu16.04
DataNucleus starting with Gradle
Jigsaw notes in Gradle
Use WebJars with Gradle
Get started with Gradle
Use jlink with gradle
Implementing a large-scale GraphQL server in Java with Netflix DGS
Gradle settings memo (multi-project to all in one) for myself
Create a jar file that can be executed in Gradle
I made a plugin to execute jextract with Gradle task
In Ruby you can define a method with any name
Run PHP-FPM with OPcache enabled in a Read Only container
I searched for a web framework with Gem in Ruby
Create a SlackBot with AWS lambda & API Gateway in Java
Set up Gradle multi-project in IntelliJ to build JAR file
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
How to set up a proxy with authentication in Feign
Find the number of days in a month with Kotlin
Create a simple DRUD application with Java + SpringBoot + Gradle + thymeleaf (1)