IDEA使用Gradle构建SpringBoot项目工程的详细教程

网友投稿 596 2022-11-27


IDEA使用Gradle构建SpringBoot项目工程的详细教程

背景

最近在研究搭建spring源码调试环境时,接触到到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-cUHcPUore"

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打包

总结


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:springboot+mybatis配置clickhouse实现插入查询功能
下一篇:Spring boot整合连接池实现过程图解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~