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
I have uploaded the sample code to Github. https://github.com/tYoshiyuki/java-gradle-multiproject
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 |
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.
settings.gradle
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.
build.gradle
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