欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

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

时间:2022-02-28 09:21:32|栏目:JAVA代码|点击:

背景

最近在研究搭建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-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打包

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

总结

上一篇:Java解压缩zip - 解压缩多个文件或文件夹实例

栏    目:JAVA代码

下一篇:Linux下Hbase安装配置教程

本文标题:IDEA使用Gradle构建SpringBoot项目工程的详细教程

本文地址:http://www.codeinn.net/misctech/194830.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有