I have a custom `Gradle` plugin in buildSrc and wo...
# gradle
n
I have a custom
Gradle
plugin in buildSrc and would like to use it inside plugins block in one of precompiled scripts but the IDE throws an exception like my plugin is not found unless I declare it as follows
Copy code
apply<LibraryCommonPlugin>()
but one below is not working
Copy code
plugins {
    id("libraryPlugin")
}
is there any way to do so?
c
the second example uses the plugin ID that you chose in your build.gradle.kts in buildSrc.
n
Yes using exact the same id but it is not working
my plugin definition
Copy code
gradlePlugin {
    plugins {
        register("LibraryCommonPlugin") {
            id = "libraryPlugin"
            implementationClass = "LibraryCommonPlugin"
        }
    }
}
c
Try with ‘create’ instead of ‘register’. Docs.
n
sure
v
I assume your
LibraryCommonPlugin
and your precompiled script plugin are both in
buildSrc
? This cannot work, it is kind of a hen-and-egg situation. To generate the type-safe accessors for the Kotlin DSL precompiled script plugin, it needs to apply the plugin to a dummy project, but it cannot apply the plugin because it isn't built yet as it is built by the same build. Applying by class is not a problem, because there it is only needed at runtime. You can apply one precompiled script plugin from a sibling precompiled script plugin though, but I assume that is an explicitly supported special case.
n
yeah thanks for explaining the behind the scene!
176 Views