JAVA 일반 Gradle 시작하기

2015.07.26 18:17

졸리운_곰 조회 수:392

 

gradle.png

 

Gradle 시작하기

Maven 을 대체할수 있는 Groovy DSL 기반 어쩌구 저쩌구 하는데.. 다 됐고! Spring 이 빌드 시스템을 Maven 에서 Gradle 로 변경했다고 한다.

Gradle 이 왜 Maven 보다 좋은지, 왜 사용해야하는지를 알고 싶다면 글 마지막 부분에 있는 여기 를 참고하도록 하자.
 

1. Installing Gradle

먼저 여기 를 통해 Gradle 을 다운받자. 바이너리를 받으면 되고 이후에는 적당한 폴더에 압축을 풀면 된다. 그 후에는 가이드 를 따라서 환경변수를 등록하면 된다. 내 경우에는 C:\gradle 에 설치를 했다.
 

// 환경변수 추가
GRADLE_HOME - 'C:\gradle'
Path - 'C:\gradle\bin'

cmd > gradle -v // 터미널에서 Gradle 버전 확인
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------

Build time:   2013-12-17 09:28:15 UTC
Build number: none
Revision:     36ced393628875ff15575fa03d16c1349ffe8bb6

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.7.0_45 (Oracle Corporation 24.45-b08)
OS:           Windows 7 6.1 x86

 

2. Installing Gradle on STS

이건 더 쉽다. Sping Tool Suite 에서 Dashboard -> Install Extension -> Gradle Support
 

3. Making Build Script

Gradle BuildProjectTask 라는 단위로 나누어진다. 하나의 Build는 여러개의 Project로 나뉠 수 있고 다시 Project는 하나 이상의 Task 로 나뉠 수 있다. Project는 웹 어플리케이션 배포나, Jar 컴파일등의 작업으로 볼 수 있고 이걸 하기 위해서 진행되는 세부적인 작업이 Task라고 보면 된다. 좀 더 정확한 설명을 위해 원문을 첨부한다.
 

Everything in Gradle sits on top of two basic concepts: projects and tasks.
 

Every Gradle build is made up of one or more projects. A project represents some component of your software which can be built. What this means exactly depends on what it is that you are building. For example, a project might represent a library JAR or a web application. It might represent a distribution ZIP assembled from the JARs produced by other projects. A project does not necessarily represent a thing to be built. It might represent a thing to be done, such as deploying your application to staging or production environments. Don’t worry if this seems a little vague for now. Gradle’s build-by-convention support adds a more concrete definition for what a project is.
 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

Each project is made up of one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating javadoc, or publishing some archives to a repository.


그럼 실제 스크립트를 보도록 하자. 프로젝트 내에 build.gradle 파일이 하나씩 존재하며 gradle build처럼 실행시킬 수 있다.build란 단어 대신에 다른task 이름이 올 수 있다. gradle task1 처럼.

 
// gradle.build 
// created by STS Gradle Extension with Java Quickstart Option

// Java, Eclipse Project
apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.5
version = '1.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
    }
}

// Maven Repository 사용
repositories {
    mavenCentral() 
}

// 사용하는 Maven Repository 지정
dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

test {
    systemProperties 'property': 'value'
}

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'
       }
    }
}


gradle test 를 통해 테스트만 실행하거나, gradle build를 통해 테스트를 포함해서 빌드를 실행할 수 있다.


다음번에는 조금 더 자세히 빌드 스크립트에 대해서 알아보겠다.

 

4. 후기

Gradle 에선 Groovy 를 사용한다는데 중간에 Gradle User Guide 보다가 소름 돋아서 후기를 남긴다. 디렉토리 이름을 받아 존재하는 파일들을 배열로 돌려주는 Groovy 코드.
 

File[] fileList(String dir) {
    file(dir).listFiles({file -> file.isFile() } as FileFilter).sort()
}

이게 함수형 언어를 사용하는 진짜 이유다. Java 였다면 얼마나 코드가 길어졌을까..

 

References

  1. Maven을 넘어 Gradle로 가자
  2. Gradle을 이용한 빌드 자동화
  3. Gradle User Guide

 

[출처] http://anster.tistory.com/141

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
90 GC example: draw a thick line : 2D « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 234
89 SWT Draw 2D : 2D « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 158
88 SWT Button Action : Button « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 146
87 SWT Button : Button « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 193
86 SWT XML Editor: Modify DOM : Text « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 259
85 Demonstrates TreeEditor : Tree « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 218
84 Gradle을 이용하여 Java 프로젝트 빌드하기 졸리운_곰 2015.07.26 383
83 gradle을 이용한 빌드 자동화 file 졸리운_곰 2015.07.26 585
82 Maven을 넘어 Gradle로 가자. 졸리운_곰 2015.07.26 326
» Gradle 시작하기 file 졸리운_곰 2015.07.26 392
80 REST with Java (JAX-RS) using Jersey - Tutorial file 졸리운_곰 2015.07.16 433
79 Tutorial – REST API design and implementation in Java with Jersey and Spring file 졸리운_곰 2015.07.16 830
78 12.2. Using REST in Java 졸리운_곰 2015.07.16 230
77 apache XERCES2-J Source and Binary file 졸리운_곰 2015.07.16 150
76 Multithreading in java with examples 졸리운_곰 2015.07.15 195
75 Communication between parent and child thread in Java 졸리운_곰 2015.07.15 215
74 Java - Interthread Communication 졸리운_곰 2015.07.15 196
73 JAVA 로 Shell 실행하기~ 졸리운_곰 2015.07.12 448
72 JAVA에서 쉘프로그램 실행시키기 졸리운_곰 2015.07.12 5555
71 JAVA Telnet 프로그램 코드 졸리운_곰 2015.07.12 913
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED