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

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
29 Creating a TreeViewer 졸리운_곰 2015.08.06 207
28 SWT Tree Simple Demo file 졸리운_곰 2015.08.06 207
27 Create TreeView based on your own tree node structure : TreeViewer « SWT « Java Tutorial 졸리운_곰 2015.08.05 238
26 The general way to use a TreeViewer: 졸리운_곰 2015.08.05 205
25 Demonstrates TreeViewer file 졸리운_곰 2015.08.05 393
24 https://xerces.apache.org/xerces2-j/faq-dom.html#faq-4 file 졸리운_곰 2015.07.28 223
23 Use of Java2D on SWT or Draw2D graphical context : 2D « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 277
22 SWT 2D Chart: Flowchart : 2D « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 332
21 SWT Paint Example : 2D « SWT JFace Eclipse « Java 졸리운_곰 2015.07.28 236
20 Draw an X using AWT Graphics : SWT Swing AWT « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 243
19 Demonstrates a Canvas : Canvas « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 207
18 GC example: draw a thick line : 2D « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 234
17 SWT Draw 2D : 2D « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 158
16 SWT Button Action : Button « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 146
15 SWT Button : Button « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 193
14 SWT XML Editor: Modify DOM : Text « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 259
13 Demonstrates TreeEditor : Tree « SWT JFace Eclipse « Java file 졸리운_곰 2015.07.28 218
12 [SWING] 분석에 도전해볼만한 오픈소스 WebHarvest Java WebCrawler GUI file 졸리운_곰 2015.05.20 778
11 JAVA SWT XML EDITOR sample : 자바 SWT XML 에디터 예제 file 졸리운_곰 2015.05.12 379
10 JAVA SWT 대화상자 예제 : 동적으로 컨트롤을 추가하고 삭제하는 예제 졸리운_곰 2015.05.11 345
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED