- Custom Plugin도 생성 가능함
Plugin<Project>
를 implements하고, apply메소드를 구현하면 됨
public class MyPlugin implements Plugin<Project>{
public void apply(Project project){
project.task("firstTask"){
println "this is first task"
}
project.task("secondTask"){
println "this is second task"
}
}
}
build.gradle
에서는 생성한 plugin을 아래와 같이 적용시킬 수 있음
apply plugin: MyPlugin
별도 파일로 구성시
- package에 대해 명시하고, 해당 package경로에 파일로 저장함 (buildSrc 밑에 생성)
- 파일명은 class 명과 동일하게 생성
package com.test.gradle
- 해당 파일에 Plugin과 Project에 대해 import
import org.gradle.api.Plugin
import org.gradle.api.Project
public class MyPlugin implements Plugin<Project>{
public void apply(Project project){
project.task("firstTask"){
println "this is first task"
}
project.task("secondTask"){
println "this is second task"
}
}
}
build.gradle
파일에 사용할 plugin을 import 시키고 사용
import com.test.gradle.MyPlugin
...