Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When my plugin reacts to another plugin classes from the other plugin can't be found, even though both plugins are applied to the same project #27218

Open
aSemy opened this issue Nov 30, 2023 · 1 comment
Labels
a:bug in:plugin-management re:comprehensibility reasonable errors and warnings, clear dsl, mental overload

Comments

@aSemy
Copy link
Contributor

aSemy commented Nov 30, 2023

Current Behavior

I have a plugin in buildSrc. When reacting to another plugin (Kotlin Gradle Plugin) it is not able to load classes from KGP, even though both plugins are applied to the same subproject.

Expected Behavior

I have a plugin in buildSrc. When reacting to another plugin (Kotlin Gradle Plugin) it is not able to load classes from KGP, even though because both plugins are applied to the same subproject.

If this problem can't be fixed then there should be a warning and documentation that explains this behaviour, and how to work around it.

Context (optional)

This problem causes issues with Dokkatoo adamko-dev/dokkatoo#123

https://slack-chats.kotlinlang.org/t/16097568/how-can-i-fetch-the-kotlin-project-extension-i-m-trying-to-f#6c1105ca-61cb-4e81-8da7-c5582b6a1786

Steps to Reproduce

test-classloaders.zip

// buildSrc/src/main/kotlin/myplugin.gradle.kts

import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

println("applying myplugin")

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
  try {
    val kpe = extensions.getByName("kotlin") as KotlinProjectExtension
    println("found KotlinProjectExtension $kpe")
  } catch (ex: Throwable) {
    println("failed to get KotlinProjectExtension: $ex")
  }
}
// module/build.gradle.kts

plugins {
    kotlin("jvm") version "1.9.20"
    myplugin
}
> Configure project :module
applying myplugin
failed to get KotlinProjectExtension: java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension

Weirdly if I log the available extensions, I can see that KotlinProjectExtension is present.

// buildSrc/src/main/kotlin/myplugin.gradle.kts

// ...

val allExtensions =
  project.extensions.extensionsSchema.elements.joinToString { "${it.name} ${it.publicType}" }
println("all extensions: $allExtensions")

Gradle version

8.5

Build scan URL (optional)

No response

Your Environment (optional)

No response

@cobexer
Copy link
Member

cobexer commented Nov 30, 2023

Thank you for providing a valid report.

The issue is in the backlog of the relevant team, but this area of Gradle is currently not a focus one, so it might take a while before a fix is made.


Yes, the error message should be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug in:plugin-management re:comprehensibility reasonable errors and warnings, clear dsl, mental overload
Projects
None yet
Development

No branches or pull requests

2 participants