Hey detekt team, I have a question that is not abo...
# detekt
a
Hey detekt team, I have a question that is not about detekt functionality but about the functional tests for your plugin. I have a sample plugin that uses androids
BaseExtension
to access some information and it works fine on the my sample app project since I can find the extension via
Copy code
extensions.findByType(BaseExtension::class.java) // returns null in functional test but works fine on the actual app project
but when I use
GradleRunner
for my plugin’s functional test, the expression above returns
null
even though I can find it via:
Copy code
extensions.findByName("android") // not null in both cases
I was looking for a possible problem and found detekt project that has functional tests for android scenario and was wondering if you can suggest something. In my functional test I use this setup:
Copy code
File(projectRoot, "settings.gradle")
            .apply {
                writeText(
                    """
                    include ':app'
                    """
                )
            }
        File(projectRoot, "build.gradle")
            .apply {
                writeText(
                    """
                    buildscript {
                        repositories {
                            google()
                            mavenCentral()
                        }
                        dependencies {
                            classpath "com.android.tools.build:gradle:7.0.1"
                            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.32"
                        }
                    }
                    """
                )
            }
        val appModule = File(projectRoot, "app").apply { mkdir() }
        File(appModule, "build.gradle")
            .apply {
                writeText(
                    """
                    plugins {
                        id("com.android.application")
                        id("org.jetbrains.kotlin.android")
                        id("my.custom.plugin") // plugin under test
                    }
                    
                    android {
                        compileSdkVersion 30
                        defaultConfig {
                            applicationId "<http://my.custom.plugin.app|my.custom.plugin.app>"
                            
                            minSdkVersion 23
                            targetSdkVersion 30
                            
                            versionCode 1
                            versionName "1.0"
                        }
                    }
                    """
                )
            }
e
this would be better asked to gradle community or support, but there's a few workarounds
a
thanks for quick response, reading… I tried so many different ways and still don’t get the error. Didn’t want to ping detekt team as it is not related to detekt per se but spent a couple of days already on this issue
thank you so much for the link, that’s exactly the issue I have. Do you know by any chance what this resolution is?
Copy code
ef classpath = resolveSelfClasspath() +
            resolvePlugin('org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.10')
specifically
resolveSelfClasspath
and
resolvePlugin
?
I was able to make it work with
compileOnly
and
pluginCompileOnly
, thank you very much for the link, will continue to figure out the details 👍