Gradle入门及SpringBoot项目构建

https://blog.csdn.net/qq_27520051/article/details/90384483

一、介绍

Gradle 是一种构建工具,它抛弃了基于XML的构建脚本,取而代之的是采用一种基于 Groovy(现在也支持 Kotlin)的内部领域特定语言。

二、特点

  1. Gradle是很成熟的技术,可以处理大规模构建
  2. Gradle对多语言、多平台支持性更好
  3. Gradle关注在构建效率上
  4. Gradle发布很频繁,重要feature开发计划透明化
  5. Gradle社区很活跃,并且增加迅速

三、安装

1.官网 (https://gradle.org/install/)下载二进制文件,并解压

2.配置环境变量

Path    D:\tools\gradle-5.5.1\bin

3.验证

gradle -v

四、使用IDEA快速构建SpringBoot项目

在setting配置中设置本地仓库地址

1.创建一个Gradle项目

在这里插入图片描述
2.Type选择Gradle Project
在这里插入图片描述
3.选择Web中的Spring Web Starter
在这里插入图片描述
4.使用本地Gradle并配置本地仓库地址
在这里插入图片描述
5.项目创建完成
在这里插入图片描述

五、gradle配置及依赖方式说明

1.setting.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
    }
}
rootProject.name = 'demo' //项目名

2.build.gradle

plugins {
    id 'org.springframework.boot' version '2.1.6.RELEASE'
    id 'java'
}


apply plugin: 'io.spring.dependency-management'  //应用的插件




group = 'com.example'

version = '0.0.1-SNAPSHOT'

sourceCompatibility = '1.8'




repositories {  //远程仓库,根据先后顺序,决定优先级

maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}

mavenCentral()

}




dependencies {

implementation 'org.springframework.boot:spring-boot-starter-web'

testImplementation 'org.springframework.boot:spring-boot-starter-test'

}


3.build.gradle中各种依赖说明

1.implementation
这个指令的特点就是,对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开。

2.api
完全等同于compile指令。

3.compile
这种是我们最常用的方式,使用该方式依赖的库将会参与编译和打包。

4.testCompile
testCompile 只在单元测试代码的编译以及最终打包测试时有效。

5.debugCompile
debugCompile 只在debug模式的编译和最终的debug打包时有效。

6.releaseCompile
releaseCompile 仅仅针对Release模式的编译和最终的Release打包。

7.provided
只在编译时有效,不会参与打包,可以在自己的moudle中使用该方式依赖。

8.apk(runtimeOnly)

只在生成apk的时候参与打包,编译时不会参与,很少用。

4.依赖版本号处理

compile ‘com.google.code.gson:gson:2.8.0

在Gradle中可以不指定版本号,比如:

compile ‘com.google.code.gson:gson:2.+’ 引入gson 大版本为2的包 
compile ‘com.google.code.gson:gson:latest.release’引入gson 最新的包

5.统一管理版本号

def dpc = rootProject.ext.testVersion
ext{
    //dependencies
    testVersion ='xx.xx.xx'
}


//使用

compile test dpc


posted @   edda_huang  阅读(972)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示