Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 20645

Konfigure KotlinCompile taks from my plugin only when Kotlin plugins is initialized

$
0
0

I would like to configure Kotlions’s KotlinCompile class, but in a lazy way, only when this plugin is used by the project. So I have an only compile-time dependency on Kotlin plugin.

And then I’m trying do this:

project.tasks.matching { it::class.simpleName?.contains("KotlinCompile") ?: false}.all {
 ...
}

And even

project.plugins.matching { it::class.simpleName?.contains("KotlinAndroidPlugin") ?: false }.all {
   project.tasks.matching { it::class.simpleName?.contains("KotlinCompile") ?: false}.all {
     ...
   }
}

So I’m sure that Kotlin plugin was initialized in the time when my callback is called.
If there is no Kotlin it is not called.
But still, inside of inner lambda, I got java.lang.NoClassDefFoundError every time I tried to touch KotlinCompile class :disappointed:
I don’t understand how Gradle can add KotlinCompile task without having it loaded by classloader.

Until now we was using old good apply way, which has one big advantage, that all classes of all plugins are on classpath in the time of plugin initialisation.

So I was able do just this

    try {
        project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
               ....
        }
    } catch (NoClassDefFoundError ex) {
        project.logger.info("Skipping setupKotlinDefault because there is no Kotlin on classpath")
    }

And it works great. But now with plugins {} this way doesn’t works.


Viewing all articles
Browse latest Browse all 20645

Trending Articles