Hi, From a custom gradle plugin, I’m reacting to t...
# gradle
j
Hi, From a custom gradle plugin, I’m reacting to the kotlin plugin being applied,
pluginManager.withPlugin("org.jetbrains.kotlin.jvm")
and trying to configure the the
KotlinCompile
task
tasks.withType<KotlinCompile>().configureEach
. however, gradle says the class can’t be found. This is a JVM project. Any idea why?
m
Can you share the stacktrace? What class can't be found?
This sounds like you have different
KotlinCompile
classes in your classpath but it's hard to tell. Maybe double check you have KGP as a
compileOnly
dependency of your plugin?
j
stack
convention plugin.cpp
convention plugin build.gradle.kt
running with debug gives this in the error
Copy code
Caused by: java.lang.IllegalArgumentException: No enum constant org.jetbrains.kotlin.statistics.metrics.StringMetrics.USE_CLASSPATH_SNAPSHOT
m
Sounds like disconnects between the KGP version your plugin is expecting and the one that is applied in your project
j
i’m using gradle version catalogs
unless gradle is bringing something in i don’t see how
m
Make sure
libs.kotlinGradlePlugin
and the plugin alias you have for KGP point to the same version
j
yes
they do
m
NoClassDefFoundError
and
ClassNotFoundexception
are different. I'm assuming you got ``ClassNotFoundexception`` in debug, right?
Usually that's because you have a new Gradle daemon. The first time the JVM chokes on a class, it'll throw
ClassNotFoundexception
and after that, it "remembers" and throws
NoClassDefFoundError
j
the stack is
NoClassDefFoundError
hmm
i’ll kill daemons and try not to use a daemon
m
Can you try
./gradlew stop && ./gradlew build
?
j
sure
there is no
stop
task in the project
m
woops, sorry
./gradlew --stop
j
lol just saw that, no worries, trying again
m
USE_CLASSPATH_SNAPSHOT was added here. Looks like it's new in
1.9.0
or so, maybe
1.8.20-something
j
ya i am on 1.8.20
m
The full stacktrace that leads to
org.jetbrains.kotlin.statistics.metrics.StringMetrics.USE_CLASSPATH_SNAPSHOT
would be interesting. Something else you can try is
./gradlew buildEnvironment
in your project where KGP and your convention plugin are applied and see if any odd version of KGP is there
j
stack leading to USE_CLASSPATH_SNAPSHOT
./gradlew buildEnvironment
fails before the report
m
Never easy, right? 😅
You could comment your convention plugin until it passes but not the most fun stuff to do...
j
ok no worries. thanks for your help!
m
Do you have maybe a "newer" gradle property that somehow the "older" build service does not know?
Or configuration cache maybe?
j
i just commented out a settings plugin
Plugin<Settings>
in my settings.gradle.kts and that let it pass…. i was just applying common dependency repos
i’ll dig into what its doing
thanks for pointing me somewhere
👍 1
s
if you do
Copy code
tasks.withType<KotlinCompile>().configureEach { }
then so long as
KotlinCompile
is on the classpath, it should work (it will apply the configuration to tasks added afterwards)