下载解压
配置环境变量
GRADLE_HOME:D:\dev\gradle-3.5
加入Path
%GRADLE_HOME%\bin;
保险起见记得前后加分号
校验:
命令行:
gradle -v
全局切换到阿里仓库
到自己用户目录下 我这里是C:\Users\zekk\.gradle
新建init.gradle 这里gradle为格式名
插入
allprojects{
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
remove repo
}
}
}
maven {
url REPOSITORY_URL
}
}
}
之后gradle都会从阿里仓库拉取文件了
只对单个项目生效
配置:
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
}
随便建一个springboot项目
命令行执行gradle build
默认路径就是当前项目目录
生成了jar包
用git bash 省的自己切路径
打开localhost:8080
因为是空项目 出现报错页面 ok
再进项目大概看下核心文件 build.gradle文件
//首先会执行 buildscript这段脚本
buildscript {
// ext用来定义动态属性
ext {
//下面依赖可以被引用
springBootVersion = '1.5.9.RELEASE'
}
// 默认是maven的中央仓库 可以自己配置国内镜像 gradle使用了和maven一样的仓库
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
//使用gradle的一些插件
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.waylau.spring.boot.blog'//组织公司名
version = '0.0.1-SNAPSHOT'//项目版本
sourceCompatibility = 1.8//jdk版本
repositories {//依赖使用的仓库
mavenCentral()
}
//项目里使用的jar包之类的东西 分编译时 测试时 还有仅编译时的lombok
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
gradle-wapper 可以不安装gradle 自动下载gradle
这样可以统一项目所有人的gradle的版本
假如你现在电脑没有gradle 也可以用这个wapper自动对项目进行构建
构建命令
gradlew build
开始执行gradle-wrapper.properties的配置
可以根据需要修改gradle-wrapper.properties
2018年1月25日18:30:54
未知错误:
'back\hello-world\' is not recognized as an internal or external command,
operable program or batch file.
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain