페이스북에서 SKP 팀장님으로 계시는 박성철님(http://www.facebook.com/fupfin)의 도움으로
Building and Testing with gradle 웹 버전을 알게 되어서 하나씩 보고 익히는 중
1. gradle 다운로드
- http://gradle.org/downloads.html
2. 설치
- 압축해제 후 환경설정에 $GRADLE_HOME 설정
- $GRADLE_HOME/bin을 path에 설정
3. Helloworld
//1. helloworld.gradle | |
task helloWorld << { | |
println 'hello, world' | |
} | |
//run with -b | |
gradle -b helloworld.gradle helloWorld | |
:helloWorld | |
hello, world | |
BUILD SUCCESSFUL | |
Total time: 1.615 secs | |
//run with -q -b | |
gradle -q -b helloworld.gradle helloWorld | |
hello, world | |
//2. hello world in two tasks | |
//helloworldtwotask.gradle | |
task hello << { | |
print 'hello, ' | |
} | |
task world(dependsOn: hello) << { | |
println 'world' | |
} | |
//run | |
gralde -b helloworldtwotask.gradle world | |
:hello | |
hello, :world | |
world | |
BUILD SUCCESSFUL | |
Total time: 2.421 secs |
-b 옵션은 build파일을 지정 할 수 있다. 기본은 build.gradle이다.
-q 옵션은 error레벨의 로그만 로깅한다.
-task는 두개 이상 설정이 가능하며, dependsOn 설정으로 의존관계를 설정 할 수 있다.
4. 간단한 Java 빌드 예제
//1. simpleJavaBuild.gradle | |
apply plugin: 'java' | |
//2. make Java file | |
- simpleJavaBuild.gradle | |
| | |
src - main - java - org - gradle - example - simple - HelloWorld.java | |
//3. HelloWorld.java | |
package org.gradle.example.simple; | |
public class HelloWorld { | |
public static void main(String args[]) { | |
System.out.println("Hello World"); | |
} | |
} | |
//4. build with gradle | |
gradle -b simpleJavaBuild.gradle build | |
:compileJava | |
:processResources UP-TO-DATE | |
:classes | |
:jar | |
:assemble | |
:compileTestJava UP-TO-DATE | |
:processTestResources UP-TO-DATE | |
:testClasses UP-TO-DATE | |
:test | |
:check | |
:build | |
BUILD SUCCESSFUL | |
Total time: 3.058 secs |
- apply plugin: 'java'라는 내용으로 simpleJavaBuild.gradle 파일을 만든다.
- 위와 같은 디렉토리 구조로 HelloWorld.java 파일을 생성한다.
- build task를 실행한다.
5. build 후 디렉토리 구조
출처 : http://www.gradleware.com/registered/books/building-and-testing/hello-gradle.html
6. gradle --help를 치면, command line 리스트를 볼 수 있다.
https://github.com/need4spd/gradletest.git