Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amitmisra16/gradle-multi-module-project
Springboot 2.x with Gradle 6.x multi-module setup using conventions
https://github.com/amitmisra16/gradle-multi-module-project
conventions gradle multimodule spring-boot
Last synced: 21 days ago
JSON representation
Springboot 2.x with Gradle 6.x multi-module setup using conventions
- Host: GitHub
- URL: https://github.com/amitmisra16/gradle-multi-module-project
- Owner: amitmisra16
- Created: 2020-11-04T22:04:22.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-04T22:46:20.000Z (about 4 years ago)
- Last Synced: 2024-10-10T05:37:15.893Z (about 1 month ago)
- Topics: conventions, gradle, multimodule, spring-boot
- Language: Java
- Homepage:
- Size: 62.5 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
= Springboot with Gradle multi module project setup
Setup project using `gradle init` for the initial setup.
.Ensure latest gradle is available in current shell
[source, bash]
----$ sdk use gradle 6.7
Using gradle version 6.7 in this shell.
$ gradle -v
------------------------------------------------------------
Gradle 6.7
------------------------------------------------------------Build time: 2020-10-14 16:13:12 UTC
Revision: 312ba9e0f4f8a02d01854d1ed743b79ed996dfd3Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 1.8.0_265 (Oracle Corporation 25.265-b01)
OS: Linux 5.4.0-52-generic amd64----
.Check JDK version
[source,bash]
----
$ java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
----.Using gradle init for generating multi-module folder structure
[source,bash]
----
$ gradle initSelect type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6] 3Split functionality across multiple subprojects?:
1: no - only one application project
2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 2Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1Project name (default: gradle-multi-module-project):
Source package (default: gradle.multi.module.project):> Task :init
Get more help with your project: https://docs.gradle.org/6.7/samples/sample_building_java_applications_multi_project.htmlBUILD SUCCESSFUL in 27s
2 actionable tasks: 2 executed
----.Checking multi-module project structure
[source,bash]
----
$ ./gradlew -q projects------------------------------------------------------------
Root project
------------------------------------------------------------Root project 'gradle-multi-module-project'
+--- Project ':app'
+--- Project ':list'
\--- Project ':utilities'To see a list of the tasks of a project, run gradlew :tasks
For example, try running gradlew :app:tasks
----.Executing gradle build
[source,bash]
----
$ ./gradlew buildBUILD SUCCESSFUL in 27s
10 actionable tasks: 10 executed
----.Add springboot plugin and dependency management plugin dependencies to buildscr/build.gradle
[source,groovy]
----
dependencies {
implementation('org.springframework.boot:spring-boot-gradle-plugin:2.3.3.RELEASE')
implementation('io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE')
}
----.Adding springboot and dependency manager plugins to java application convention script
[source,groovy]
----
plugins {
// Apply the common convention plugin for shared build configuration between library and application projects.
id 'gradle.multi.module.project.java-common-conventions'
// Apply the application plugin to add support for building a CLI application in Java.
// id 'application'
// Overriding application plugin with springboot gradle plugin
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
----.Adding springboot application annotation to App.java
[source,java]
----
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class App {
public static void main(String[] args) {
LinkedList tokens;
tokens = split(getMessage());
System.out.println(join(tokens));
}
}
----.Using application convention for defining springboot and Junit dependencies
[source,groovy]
----
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}bootJar {
enabled = true
}
----.Gradle build for multi-module projects post convention and build.gradle changes
[source,bash]
----# Running springboot application
$ ./gradlew clean build && ./gradlew :app:bootRun
BUILD SUCCESSFUL in 6s
13 actionable tasks: 13 executed> Task :app:bootRun
Hello World!BUILD SUCCESSFUL in 1s
6 actionable tasks: 1 executed, 5 up-to-date----