Hello I'm trying to make a kotlin js plugin it use...
# javascript
v
Hello I'm trying to make a kotlin js plugin it uses kotlin(gradle-plugin) dependency. I've published it to the local maven repository and when I'm trying to access it in a new project i get
Copy code
Caused by: org.gradle.api.UnknownTaskException: Task with name 'kotlinNodeJsSetup' not found in root project 'testproject'.
Here is my plugin class
Copy code
class TailwindPlugin: Plugin<Project> {
    override fun apply(target: Project) {
        val extension = target.extensions.create(
            "copyConfigFiles",
            TailwindPluginExtension::class.java
        )
        target.tasks.register(
            "copyConfigFiles",
            CopyConfigsTask::class.java
        ) {
            this.group = "kizzy"
            this.description = "Copies tailwind,postcss files to build directory"
            tailwindConfig.set(extension.tailwindConfig)
            postCssConfig.set(extension.postCssConfig)
        }

        val kotlinNodeJsSetup by target.rootProject.tasks.getting(NodeJsSetupTask::class)
        val kotlinNpmInstall by target.rootProject.tasks.getting(KotlinNpmInstallTask::class)
        // Move files 
     }
}
b
You're initiating your plugin too early - kotlin plugin was not applied yet
Try putting init logic inside project.plugins.withId
You can browse through npm-publish plugin for inspiration. It too integrates with kjs plugin. petuska.dev/npm-publish
v
I am applying it in my other module like alias(libs.plugins.kizzy.tailwind)
It's a kotlin plugin mostly which is targeting KotlinJS projects
b
Doesn't matter. The plugin should not rely on the consumer applying it in the correct order.
That's why gradle provides APIs to handle application race conditions and dependencies appropriately
v
It's not a js plugin it's a plugin which copies some file to other location why would I need to check npm publish. I'm not publishing any js files with it
b
I know, it's a gradle plugin that depends on kotlin plugin
And I'm not saying to use npm-publish, only to browse it's source code as it's doing similar things to your plugin
v
Ok went through that repo. I think I'm also doing the same thing, but I'm using getting to get those Tasks, can that be the issue ?
Maybe i have to use afterEvaluate
Oh wow it seems to be working after I put my copying logic in afterEvaluate. Thanks @Big Chungus. Also I was wondering why I can't use this plugin from inside my buildSrc. Since this plugin needs those nodejs setup and npm install tasks I had to use kotlin("gradle-plugin") which then leads to error saying multi-platform version mismatch
a
@Ilya Goncharov [JB] ^^