
buildscript {
    ext {
        springBootVersion = '2.3.7.RELEASE'
        lombokVersion = '1.18.10'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'gradle.test.javaapp'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
    mavenCentral()
    jcenter()
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    // api '...'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    compileOnly "org.projectlombok:lombok:$lombokVersion"
    // runtimeOnly '...'
    annotationProcessor "org.projectlombok:lombok:$lombokVersion"
}
// gradle hello 명령어로 실행
task hello {
  println 'Hello Gradle' 
}
task hello {
  doFirst {
    // task 내에서 doLast보다 먼저 처리될 내용
    println 'Hello'
  }
  doLast {
    // task 내에서 doFirst보다 나중에 처리될 내용
    println 'Gradle'
  }
}
task calc {
   def s= s
   def x = x.toInteger()
   def y = y.toInteger()
 
   if (s =='+') {
      println x + '+' + y + '=' + (x+y)
   } else if (s == '-') {
      println x + '-' + y + '=' + (x-y)
   } else if (s == 'x') {
      println x + 'x' + y + '=' + (x * y)
   } else {
      println x + '/' + y + '=' + (x/y)
   }
}
task hello {
    println 'Hello gradle'
   
    doLast {
        println 'Good bye~'
        // tasks.다른태스크명.execute()
        tasks.otherTask.execute()
    }
    doFirst {
        println 'Nice meet you.'
    }
}
 
task otherTask {
    println 'do other task'
}
// 방법 1
task 태스크명(dependsOn : ‘다른태스크명’) {
    // 내용
}
task 다른태스크명 {
    // 내용
}
// 방법 2
task 태스크명 {
dependsOn : ‘다른태스크명’
    // 내용
}
task 다른태스크명 {
    // 내용
}
// 예시
task hello(dependsOn:'otherTask') {
    println 'Hello gradle'
   
    doLast {
        println 'Good bye~'
        tasks.otherTask.execute()
    }
    doFirst {
        println 'Nice meet you.'
    }
}
 
task otherTask {
    doLast{
       println 'do other task'
   }
}
// mulit-module 모듈 예시
rootProject.name = 'multi-module'
include 'library'
include 'application'
dependencies {
    // Local 라이브러리 모듈 or 프로젝트에 대한 종속성을 정의
    implementation project(":mylibrary")
    // Local 바이너리 라이브러리에 대한 종속성을 정의
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // Remote 바이너리 라이브러리에 대한 종속성을 정의
    implementation 'org.springframework.boot:spring-boot-starter'
}
// library 모듈 예시
plugins {
	id 'org.springframework.boot' version '2.5.2'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
	mavenCentral()
}
// 설정 부분
bootJar {
	enabled = false
}
jar {
	enabled = true
}
//
dependencies {
	implementation 'org.springframework.boot:spring-boot-starter'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
// application 모듈 예시
plugins {
	id 'org.springframework.boot' version '2.5.2'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
	mavenCentral()
}
dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	implementation 'org.springframework.boot:spring-boot-starter-web'
  
  // library 의존성 추가
	implementation project(':library')
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
참고 1 : https://velog.io/@franc/Gradle-%EA%B8%B0%EB%B3%B8%EC%82%AC%EC%9A%A9%EB%B2%95
참고 2 : https://blog.naver.com/sharplee7/221413629068
참고 3 : https://kimpaper.github.io/2016/07/14/gradle/
참고 4 : https://tecoble.techcourse.co.kr/post/2021-09-06-multi-module/