当前位置:   article > 正文

使用Gradle构建spring-boot多模块项目_./gradlew bootjar

./gradlew bootjar
一、目录结构
.
├── boogle-common
│   ├── build.gradle.kts
│   └── src
├── boogle-core
│   ├── build.gradle.kts
│   └── src
├── boogle-generator
│   ├── build.gradle.kts
│   └── src
├── boogle-logging
│   ├── build.gradle.kts
│   └── src
├── boogle-quartz
│   ├── build.gradle.kts
│   └── src
├── boogle-system
│   ├── build.gradle.kts
│   └── src
├── boogle-web-starter
│   ├── build.gradle.kts
│   └── src
├── buildSrc
│   ├── build
│   ├── build.gradle.kts
│   └── src
│       └── main
│           └── kotlin
│               └── org.wm.java-conventions.gradle.kts
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle.kts
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
二、引入spring-boot相关依赖

buildSrc/build.gradle.kts

plugins {
    `kotlin-dsl`
  	// spring-boot 依赖管理插件
    id("org.springframework.boot") version "2.7.3"
}
// spring-boot 依赖管理插件
apply(plugin = "io.spring.dependency-management")

// 指定启动类
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootJar>("bootJar") {
    mainClass.set("org.wm.WebAppApplication")
}
// 自定义slf4j版本
extra["slf4j.version"] = "1.7.20"
repositories {
    maven {
        url = uri("https://plugins.gradle.org/m2/")
    }
    gradlePluginPortal()
}
dependencies {
  // spring-boot插件依赖
    implementation("org.springframework.boot:spring-boot-gradle-plugin:2.7.3")
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

buildSrc/src/main/kotlin/org.wm.java-conventions.gradle.kts

import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
    `java-library`
    `maven-publish`
    id("org.springframework.boot")
}
apply(plugin = "io.spring.dependency-management")

tasks.named<BootJar>("bootJar") {
    mainClass.set("org.wm.WebAppApplication")
}

repositories {
    mavenLocal()
    maven {
        url = uri("https://maven.aliyun.com/repository/public/")
    }
    maven {
        url = uri("https://repo.maven.apache.org/maven2/")
    }
}

dependencies {
    api("org.springframework.boot:spring-boot-starter-web")
    api("org.springframework.boot:spring-boot-configuration-processor")
    api("org.projectlombok:lombok:1.18.24")
    annotationProcessor("org.projectlombok:lombok:1.18.24")
    testAnnotationProcessor("org.projectlombok:lombok:1.18.24")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("io.projectreactor:reactor-test:3.4.17")
}

group = "org.wm"
version = "1.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
publishing {
    publications.create<MavenPublication>("maven") {
        from(components["java"])
    }
}
tasks.withType<JavaCompile>() {
    options.encoding = "UTF-8"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
三、子项目依赖

boogle-common/build.gradle.kts

plugins {
    id("org.wm.java-conventions")
}
dependencies {
    api(project(":boogle-core"))
    api("org.springframework.boot:spring-boot-starter-aop")
    api("org.springframework.boot:spring-boot-starter-data-redis")
}

description = "通用工具模块"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

boogle-core/build.gradle.kts

plugins {
    id("org.wm.java-conventions")
}
dependencies {
    api("org.springframework.boot:spring-boot-starter-security")
    testImplementation("org.springframework.security:spring-security-test:5.6.3")
}
description = "核心模块"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
四、settings.gradle.kts配置
rootProject.name = "XunLuAdmin"
include(":boogle-core")
include(":boogle-system")
include(":boogle-web-starter")
include(":boogle-logging")
include(":boogle-generator")
include(":boogle-quartz")
include(":boogle-common")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
五、打包
./gradlew bootJar
  • 1

如果使用IDEA可以直接点击/Tasks/build/bootJar任务打包。

六、参考文档

spring-boot插件地址

Spring-boot依赖配置地址

Gradle官方文档

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/305652
推荐阅读
相关标签
  

闽ICP备14008679号