DEV Community

Discussion on: Writing Gradle Plugins for Android; or, Donald Trump is a Huge Tool

Collapse
 
tomkoptel profile image
tomkoptel

Hello Tony!

Nice and funny article :D
I have a question maybe you can help. I am trying to setup the plugin as a composite build. I have also used compileOnly to specify Android plugin sources. The issue appears when I do execute the test with Gradle Test Kit.

I have the following setup.

app/
build-src/my-plugin/build.gradle.kts
build-src/settings.gradle.kts
build-src/build.gradle.kts
settings.gradle.kts
gradlew
Enter fullscreen mode Exit fullscreen mode

build-src/my-plugin/build.gradle.kts

plugins {
    kotlin("jvm") version "1.3.72"
    id("java-gradle-plugin")
    `kotlin-dsl`
}

val pluginVersion = "1.0"
version = pluginVersion

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation(gradleApi())
    compileOnly("com.android.tools.build:gradle:4.0.2")
    testImplementation("junit:junit:4.13.1")
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

gradlePlugin {
    plugins {
        val pluginId = "com.my.plugin"
        create(pluginId) {
            id = pluginId
            implementationClass = "$pluginId.AndroidKeystorePlugin"
            version = pluginVersion
        }
    }
}
Enter fullscreen mode Exit fullscreen mode
abstract class AndroidKeystorePlugin : Plugin<Project> {
    override fun apply(project: Project) {
        project.plugins.withType(AppPlugin::class.java) {
            val extension = project.extensions.getByType(BaseAppModuleExtension::class.java)
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

When I do execute cd build-src/my-plugin/ && ../../gradlew test I do receive an error.

Could not generate a decorated class for type AndroidKeystorePlugin. com/android/build/gradle/BaseExtension

Any ideas why this happens?

Collapse
 
autonomousapps profile image
Tony Robalik

Hey, thanks for asking. I would suggest joining the gradle community slack, which is open to all, and you could ask in either the #plugin-development or #android channels.

Collapse
 
tomkoptel profile image
tomkoptel

Thanks Tony!