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

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構建SpringBoot項目工程
新建SpringBoot項目

使用Gradle構建項目

項目結構
- src結構和maven結構一致;gradle文件夾 存放gradle wrapper相關文件;build.gradle相當于maven里面的pom.xml,setting.gradle用于多模塊的配置。

build.gradle
- plugins:插件配置;
- sourceCompatibility:jdk版本號
- repositories:倉庫配置,mavenCentral()代表中央倉庫;
- dependencies:依賴的坐標集合
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打包



總結
到此這篇關于IDEA使用Gradle構建SpringBoot項目工程的文章就介紹到這了,更多相關IDEA構建SpringBoot項目工程內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
SpringCloud創(chuàng)建多模塊項目的實現(xiàn)示例
,Spring Cloud作為一個強大的微服務框架,提供了豐富的功能和組件,本文主要介紹了SpringCloud創(chuàng)建多模塊項目的實現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下2024-02-02
SpringBoot @ConfigurationProperties使用詳解
這篇文章主要介紹了SpringBoot @ConfigurationProperties使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-02-02
mybatis insert 返回自增主鍵的實現(xiàn)示例
mybatis 在新增之后怎么也獲取不到自增主鍵,本文主要介紹了mybatis insert 返回自增主鍵的實現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下2024-06-06

