首页 技术 正文
技术 2022年11月16日
0 收藏 436 点赞 3,609 浏览 1746 个字

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
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898