Last active
July 2, 2018 02:17
-
-
Save Curookie/fd0e96c09245a3f0c212f76e2993d6b0 to your computer and use it in GitHub Desktop.
I LOVE JAVA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
개요? | |
- gradle은 maven과 양대산맥으로 프로젝트 개발 환경을 구축해주는 녀석이라고 보면 된다. Maven과 Ivy를 지원한다. | |
- JAVA를 기반으로 하고 있으며, 모든 빌드 단계는 task로 정의하며, 상당부분 Closure로 구현되어 있다. | |
뭐니? | |
- build.gradle 이라는 파일안에 gradle문법(Groovy)으로 요청한대로 환경을 구축해준다. | |
+ settings.gradle 파일은 싱글프로젝트 or 멀티프로젝트 구성에 대해 정의 하는 파일. | |
왜 필요? | |
- 스프링, 안드로이드 등등 쓰이는 용도가 다양하니 꼭 숙지해둬야함 | |
문법 | |
1. apply plugin: ~ | |
- 사용하고자 하는 gradle 플러그인을 프로젝트에 적용한다. | |
ex) | |
apply plugin: 'java' | |
apply plugin: 'eclipse' | |
2. buildDir = ~ | |
- buildDir를 프로젝트에 상대적인 경로로 바꿔줄 수 있다. | |
ex) | |
buildDir = 'build' | |
buildDir = 'target' | |
3. repositories { | |
mavenCentral() | |
} | |
- 디펜던시를 가져올 레파지토리(웹사이트 공간)를 정한다. 보통 mavenCentral()이다. | |
- dependencies 선언된 파일이 다운로드 되는 로컬 위치는 아래와 같다. | |
C:\Users\사용자명\.gradle\caches\modules-2\files-2.1\junit\junit\4.12 | |
C:\Users\사용자명\.m2 | |
ex) | |
repositories { | |
mavenCentral() | |
} | |
4. dependencies { | |
compile group: 'commons-collections', name: 'commons-collections', version: '3.2' | |
testCompile group: 'junit', name: 'junit', version: '4.+' | |
} | |
- repositories와 함께 보면 되는 문법으로 사용할 디펜던시(라이브러리)를 적어주는 곳이다. | |
ex) | |
dependencies { | |
compile group: 'commons-collections', name: 'commons-collections', version: '3.2' | |
testCompile group: 'junit', name: 'junit', version: '4.+' | |
} | |
5. ext | |
{ 변수명 = "~" | |
} | |
- 프로젝트 전체와 서브 프로젝트에서도 접근이 가능한 변수 선언 | |
ex) ext { | |
sprintVersion = "3.4.0.RELEASE" | |
emailNotification = "[email protected]" | |
} | |
6. buildscript { | |
~ | |
} | |
- Gradle에서 제공 되는 빌드 기능 이외의 직접 만든 Plugin 기능이나 외부 기능(외부 라이브러리)을 사용하고자 한다면 추가로 정의, 안에는 보통 repositories와 dependencies가 들어간다. | |
ex) | |
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE' | |
} | |
} | |
7. sourceCompatibility = ~ | |
- Java 호환 버전을 ~로 설정 | |
ex) sourceCompatibility = 1.8 | |
8. task ~ { | |
~ | |
} | |
- 특정 작업을 할 테스크를 선언한다. | |
ex) /** spring-boot에서 src 폴더 자동 생성 **/ | |
task initSourceFolders { | |
sourceSets*.java.srcDirs*.each { | |
if( !it.exists() ) { | |
it.mkdirs() | |
} | |
} | |
sourceSets*.resources.srcDirs*.each { | |
if( !it.exists() ) { | |
it.mkdirs() | |
} | |
} | |
} | |
9. jar { | |
~ | |
} | |
- gradle의 jar 테스크 build시 build/libs에 jar로 배포되는 jar의 빌드 설정하는 부분. | |
ex) | |
jar { | |
manifest { | |
attributes 'Title': 'My Application', 'Version': version, 'Main-Class': 'com.ecru.Application' | |
} | |
archiveName 'MyApp.jar' | |
dependsOn configurations.runtime | |
from { | |
configurations.compile.collect {it.isDirectory()? it: zipTree(it)} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment