🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Directory Structure
Here’s the directory structure we’ll create for our "Blogger" project:
├── gradle
├── gradlew
├── settings.gradle.kts
├── build-logic
│ ├── settings.gradle.kts
│ └── conventions
│ ├── build.gradle.kts
│ └── src/main/kotlin/shared-build-conventions.gradle.kts
├── blogger-core
│ └── build.gradle.kts
├── blogger-common
│ └── build.gradle.kts
├── blogger-web
│ └── build.gradle.kts
└── documentation
└── build.gradle.kts
Step-by-Step Guide
Step 1: Create the Project Directory
First, create the main project directory and navigate into it.
mkdir blogger-project
cd blogger-project
Step 2: Create Subdirectories
Next, create the necessary subdirectories for the project.
mkdir -p build-logic/conventions/src/main/kotlin
mkdir blogger-core blogger-common blogger-web documentation
touch settings.gradle.kts
touch build-logic/settings.gradle.kts
touch build-logic/conventions/build.gradle.kts
touch build-logic/conventions/src/main/kotlin/shared-build-conventions.gradle.kts
touch blogger-core/build.gradle.kts
touch blogger-common/build.gradle.kts
touch blogger-web/build.gradle.kts
touch documentation/build.gradle.kts
Step 3: Initialize Gradle Wrapper
Initialize the Gradle wrapper in your project directory.
gradle wrapper
This will create the gradlew scripts and the gradle directory.
Step 4: Configure settings.gradle.kts
Configure the root settings file to include all modules.
rootProject.name = "blogger-project"
include(":build-logic")
include(":blogger-core")
include(":blogger-common")
include(":blogger-web")
include(":documentation")
Step 5: Configure build-logic/settings.gradle.kts
Set the name for the build logic project.
rootProject.name = "build-logic"
Step 6: Create Shared Build Conventions
Create shared build conventions in the build logic module.
build-logic/conventions/build.gradle.kts
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
build-logic/conventions/src/main/kotlin/shared-build-conventions.gradle.kts
Define shared conventions for the project.
plugins {
java
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
testImplementation("junit:junit:4.13.2")
}
Step 7: Configure Sub-Modules
Configure each sub-module with its respective build.gradle.kts file.
blogger-core/build.gradle.kts
plugins {
id("java")
}
repositories {
mavenCentral()
}
dependencies {
implementation(project(":blogger-common"))
testImplementation("junit:junit:4.13.2")
}
blogger-common/build.gradle.kts
plugins {
id("java")
}
repositories {
mavenCentral()
}
dependencies {
testImplementation("junit:junit:4.13.2")
}
blogger-web/build.gradle.kts
plugins {
id("java")
id("war")
}
repositories {
mavenCentral()
}
dependencies {
implementation(project(":blogger-core"))
implementation(project(":blogger-common"))
testImplementation("junit:junit:4.13.2")
}
documentation/build.gradle.kts
plugins {
id("java")
}
repositories {
mavenCentral()
}
dependencies {
testImplementation("junit:junit:4.13.2")
}
Conclusion
In this guide, we have set up a Gradle multi-module project for the "Blogger" application. Each module has its own build.gradle.kts file, and we've created a shared build logic module to define common build conventions. This structure helps organize and manage the build process efficiently.
Feel free to customize and expand upon this structure to suit your project's specific needs. Happy coding!
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment