plugins {
id 'org.jetbrains.kotlin.jvm' version '1.7.0'// Kotlin
}
dependencies {
implementation gradleApi()
}
repositories {
google()
mavenCentral()
}
open class FirstPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.create("testPlugin", MyTask::class.java) {
it.group = "channel"
it.description = "插件测试"
}
}
}
open class MyTask : DefaultTask() {
@TaskAction
fun doSomething() {
val android = project.extensions.findByName("android")
val def = DefaultGroovyMethods.getAt(android, "defaultConfig")
println("def===========$def")
val version = DefaultGroovyMethods.getAt(def, "versionCode")
val applicationId = DefaultGroovyMethods.getAt(def, "applicationId")
println("version=======$version")
println("applicationId=======$applicationId")
}
}