Java
Beginner
1 min read
Multi-module Builds and Dependency Management
Example
// ---- Maven multi-module structure ----
// Root pom.xml
// <modules>
// <module>core</module>
// <module>api</module>
// </modules>
//
// core/pom.xml — child module (excerpt)
// <parent>
// <groupId>com.example</groupId>
// <artifactId>my-app</artifactId>
// <version>1.0.0</version>
// </parent>
// <artifactId>core</artifactId>
// ============================================================
// Gradle multi-project: settings.gradle
// ============================================================
// rootProject.name = 'my-app'
// include(':core')
// include(':api')
// ============================================================
// api/build.gradle — depends on :core
// ============================================================
plugins {
id 'java'
}
dependencies {
implementation project(':core') // inter-project dep
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}
// ============================================================
// Root build.gradle — shared config via allprojects / subprojects
// ============================================================
subprojects {
apply plugin: 'java'
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
}
Related Resources
This is the last lesson in this section.
Create a free account to earn a certificate