IDEA使用Gradle構(gòu)建SpringBoot項目工程的詳細(xì)教程
背景
最近在研究搭建spring源碼調(diào)試環(huán)境時,接觸到到gradle項目構(gòu)建工具。由于之前習(xí)慣于maven項目的構(gòu)建,故通過此文記錄相關(guān)gradle的項目構(gòu)建知識。
Gradle
Gradle是一個構(gòu)建工具,用于管理項目依賴和構(gòu)建項目工程。Gradle拋棄了Maven的基于XML的繁瑣配置,采用特定語言Groovy的配置,大大簡化了構(gòu)建代碼的行數(shù)。
項目結(jié)構(gòu)

Plugin Sample
pluginManagement {
repositories {
gradlePluginPortal()
maven { url 'https://repo.spring.io/plugins-release' }
}
}
plugins {
id "com.gradle.enterprise" version "3.2"
id "io.spring.gradle-enterprise-conventions" version "0.0.2"
}
include "spring-aop"
include "spring-aspects"
include "spring-beans"
include "spring-context"
include "spring-context-indexer"
include "spring-context-support"
include "spring-core"
include "kotlin-coroutines"
project(':kotlin-coroutines').projectDir = file('spring-core/kotlin-coroutines')
include "spring-expression"
IDEA使用Gradle構(gòu)建SpringBoot項目工程
新建SpringBoot項目

使用Gradle構(gòu)建項目

項目結(jié)構(gòu)
- src結(jié)構(gòu)和maven結(jié)構(gòu)一致;gradle文件夾 存放gradle wrapper相關(guān)文件;build.gradle相當(dāng)于maven里面的pom.xml,setting.gradle用于多模塊的配置。

build.gradle
- plugins:插件配置;
- sourceCompatibility:jdk版本號
- repositories:倉庫配置,mavenCentral()代表中央倉庫;
- dependencies:依賴的坐標(biāo)集合
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
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'
}
}
test {
useJUnitPlatform()
}
添加依賴

項目依賴的格式為 作用范圍修飾符 ( ‘groupId:artifactId:version' )
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'
}
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa
compile ('org.springframework.boot: spring-boot-starter-data-jpa: 2.3.1 ')
}
gradle打包



總結(jié)
到此這篇關(guān)于IDEA使用Gradle構(gòu)建SpringBoot項目工程的文章就介紹到這了,更多相關(guān)IDEA構(gòu)建SpringBoot項目工程內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringCloud創(chuàng)建多模塊項目的實現(xiàn)示例
,Spring Cloud作為一個強(qiáng)大的微服務(wù)框架,提供了豐富的功能和組件,本文主要介紹了SpringCloud創(chuàng)建多模塊項目的實現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下2024-02-02
Java基礎(chǔ)教程之類數(shù)據(jù)與類方法
這篇文章主要介紹了Java基礎(chǔ)教程之類數(shù)據(jù)與類方法,本文是對類的深入探討,類數(shù)據(jù)指類的一些屬性、參數(shù)等,類方法就是類包含的功能方法,需要的朋友可以參考下2014-08-08
Java面向?qū)ο髮崿F(xiàn)汽車租賃系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Java面向?qū)ο髮崿F(xiàn)汽車租賃系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02
SpringBoot @ConfigurationProperties使用詳解
這篇文章主要介紹了SpringBoot @ConfigurationProperties使用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
mybatis insert 返回自增主鍵的實現(xiàn)示例
mybatis 在新增之后怎么也獲取不到自增主鍵,本文主要介紹了mybatis insert 返回自增主鍵的實現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下2024-06-06

