1.0 安装Gradle,参考之前文章《Gradle入门实战(Windows版)》
2.0 使用gradle 快速生成一个Java project
gradle init --type java-library
3.0 在 build.gradle文件中添加 apply plugin: 'idea'
4.0 执行命令 gradle idea
5.0 用 intellij idea 打开这个项目
双击 springframework.ipr 打开项目
6.0 拷贝代码
package hello; import org.joda.time.LocalTime; /**
* Created by sheting on 10/16/2017
*/
public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime); Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
package hello; /**
* Created by sheting on 10/16/2017
*/
public class Greeter {
public String sayHello() {
return "Hello world!";
}
}
7.0 修改gradle.build
apply plugin: 'java-library'
apply plugin: 'idea' // mainClassName 是 application的一个属性,否则会报错
apply plugin: 'application'
mainClassName = 'hello.HelloWorld' sourceCompatibility = 1.8
targetCompatibility = 1.8 repositories {
mavenCentral()
} dependencies {
compile "joda-time:joda-time:2.2"
testCompile "junit:junit:4.12"
} // 该项目生成的jar包的名字和版本,如 gs-gradle-0.1.0.jar
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
8.0 执行命令刷新依赖
gradle idea --refresh-dependencies
9.0 执行命令 gradlew run 运行程序