https://kotlinlang.org logo
#gradle
Title
# gradle
j

Justin Tullgren

09/18/2023, 7:25 PM
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

mbonnin

09/18/2023, 7:30 PM
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

Justin Tullgren

09/18/2023, 7:31 PM
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

mbonnin

09/18/2023, 7:35 PM
Sounds like disconnects between the KGP version your plugin is expecting and the one that is applied in your project
j

Justin Tullgren

09/18/2023, 7:36 PM
i’m using gradle version catalogs
unless gradle is bringing something in i don’t see how
m

mbonnin

09/18/2023, 7:36 PM
Make sure
libs.kotlinGradlePlugin
and the plugin alias you have for KGP point to the same version
j

Justin Tullgren

09/18/2023, 7:36 PM
yes
they do
m

mbonnin

09/18/2023, 7:39 PM
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

Justin Tullgren

09/18/2023, 7:40 PM
the stack is
NoClassDefFoundError
hmm
i’ll kill daemons and try not to use a daemon
m

mbonnin

09/18/2023, 7:41 PM
Can you try
./gradlew stop && ./gradlew build
?
j

Justin Tullgren

09/18/2023, 7:41 PM
sure
there is no
stop
task in the project
m

mbonnin

09/18/2023, 7:43 PM
woops, sorry
./gradlew --stop
j

Justin Tullgren

09/18/2023, 7:44 PM
lol just saw that, no worries, trying again
m

mbonnin

09/18/2023, 7:44 PM
USE_CLASSPATH_SNAPSHOT was added here. Looks like it's new in
1.9.0
or so, maybe
1.8.20-something
j

Justin Tullgren

09/18/2023, 7:45 PM
ya i am on 1.8.20
m

mbonnin

09/18/2023, 7:46 PM
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

Justin Tullgren

09/18/2023, 7:49 PM
stack leading to USE_CLASSPATH_SNAPSHOT
./gradlew buildEnvironment
fails before the report
m

mbonnin

09/18/2023, 7:52 PM
Never easy, right? 😅
You could comment your convention plugin until it passes but not the most fun stuff to do...
j

Justin Tullgren

09/18/2023, 7:55 PM
ok no worries. thanks for your help!
m

mbonnin

09/18/2023, 7:57 PM
Do you have maybe a "newer" gradle property that somehow the "older" build service does not know?
Or configuration cache maybe?
j

Justin Tullgren

09/18/2023, 7:59 PM
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

solonovamax

09/20/2023, 9:48 PM
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)
7 Views