1 下载gradle http://services.gradle.org/distributions/
下载需要的版本 ,我这里下载的是 gradle-5.4.1-all.zip, 解压
配置环境变量 ,变量值为解压的路径
path末尾加入 %GRADLE_HOME%\bin;
在cmd查看
配置gradle的 jar的下载地址
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
}
}
}
这里使用IDEA2019新建一个java项目
设置文件名称与生成路径
等待项目构建完成
目录结构如下
查看build.gradle文件
plugins {
id 'java'
}
group 'com.shj.gradle'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
编写一个测试类
package com.shj;
public class GradleTest1 {
public static void main(String[] args) {
System.out.println("hello gradle!");
}
}
修改 build.gradle
plugins {
id 'java'
id 'application'
}
group 'com.shj.gradle'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
mainClassName = 'com.shj.GradleTest1'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
其中: 加入了 application 插件
也可以设置为
apply plugin:'application'
然后设置了程序的mainClassName
这两个地方都能启动main方法