温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

IDEA使用Gradle构建SpringBoot项目工程的方法

发布时间:2020-08-12 16:12:53 来源:亿速云 阅读:1160 作者:小新 栏目:开发技术

这篇文章主要介绍了IDEA使用Gradle构建SpringBoot项目工程的方法,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

背景

最近在研究搭建spring源码调试环境时,接触到到gradle项目构建工具。由于之前习惯于maven项目的构建,故通过此文记录相关gradle的项目构建知识。

Gradle

Gradle是一个构建工具,用于管理项目依赖和构建项目工程。Gradle抛弃了Maven的基于XML的繁琐配置,采用特定语言Groovy的配置,大大简化了构建代码的行数。

项目结构

IDEA使用Gradle构建SpringBoot项目工程的方法

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项目

IDEA使用Gradle构建SpringBoot项目工程的方法

使用Gradle构建项目

IDEA使用Gradle构建SpringBoot项目工程的方法

项目结构

  • src结构和maven结构一致;gradle文件夹 存放gradle wrapper相关文件;build.gradle相当于maven里面的pom.xml,setting.gradle用于多模块的配置。

IDEA使用Gradle构建SpringBoot项目工程的方法

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()
}

添加依赖

IDEA使用Gradle构建SpringBoot项目工程的方法

项目依赖的格式为 作用范围修饰符 ( ‘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使用Gradle构建SpringBoot项目工程的方法
IDEA使用Gradle构建SpringBoot项目工程的方法

感谢你能够认真阅读完这篇文章,希望小编分享IDEA使用Gradle构建SpringBoot项目工程的方法内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI