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)文章
Java多線程并發(fā)編程 Volatile關(guān)鍵字
volatile 關(guān)鍵字是一個神秘的關(guān)鍵字,也許在 J2EE 上的 JAVA 程序員會了解多一點(diǎn),但在 Android 上的 JAVA 程序員大多不了解這個關(guān)鍵字。只要稍了解不當(dāng)就好容易導(dǎo)致一些并發(fā)上的錯誤發(fā)生,例如好多人把 volatile 理解成變量的鎖2017-05-05SpringBoot如何監(jiān)聽redis?Key變化事件案例詳解
項目中需要監(jiān)聽redis的一些事件比如鍵刪除,修改,過期等,下面這篇文章主要給大家介紹了關(guān)于SpringBoot如何監(jiān)聽redis?Key變化事件的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08File的API和常用方法詳解_動力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了File的API和常用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05詳解Java如何實(shí)現(xiàn)百萬數(shù)據(jù)excel導(dǎo)出功能
這篇文章主要為大家詳細(xì)介紹了Java如何實(shí)現(xiàn)百萬數(shù)據(jù)excel導(dǎo)出功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,需要的可以參考一下2023-02-02java子類調(diào)用父類的方法中包含子類重寫的實(shí)例方法
在本篇文章里小編給大家整理了關(guān)于java子類調(diào)用父類的方法中包含子類重寫的實(shí)例方法以及相關(guān)知識點(diǎn),需要的朋友們可以學(xué)習(xí)下。2019-09-09