ryandens / javaagent-gradle-plugin

A set of Gradle plugins to ease building Java applications that leverage instrumentation agents in development and/or in production
Apache License 2.0
47 stars 8 forks source link

Plugin is incompatible with Gradle 8.4 + Kotlin 1.6.21 since 0.4.1 #49

Closed felixscheinost closed 9 months ago

felixscheinost commented 9 months ago

This plugin unfortunately seems to incompatible with our Spring Boot 2.7.x projects since 0.4.1 (maybe due to a Kotlin plugin update?).

We use Gradle 8.4 and Kotlin 1.6.21.

0.4.0 works while 0.4.1 and all newer releases fail with:

java.lang.NoSuchFieldError: KOTLIN_STAT_ENABLED_PROPERTY
        at org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices.<clinit>(KotlinGradleBuildServices.kt:52)
        at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(KotlinPluginWrapper.kt:92)
        at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(KotlinPluginWrapper.kt:54)

Upgrading from Kotlin 1.6.21 to 1.7.0 fixes the problem but that's unfortunate as 1.6.21 is the version that is officially supported by Spring Boot 2.7.x and 3.x is a major change that can't easily be done yet for some projects.

Is there anything that can be done?

Example project https://github.com/felixscheinost/reproduce-javaagent-gradle-plugin-issue

Thanks!

ryandens commented 9 months ago

Hi @felixscheinost, thanks for pointing this out and for providing the reproducer project! I don't have a formal backwards compatibility policy for this project yet, but I'll take a look at what makes sense in the context of this issue and work on clarifying this for the future. I should have a response to you later next week

felixscheinost commented 9 months ago

Yeah, I understand that with Kotlin it is a little bit difficult to keep backwards compatibility sometimes. It may also not be worth it, if it means restricting the library code too much. But maybe there is a solution and if not I maybe a test could be added which tests a baseline of compatible versions.

ryandens commented 9 months ago

👋 Hi @felixscheinost, I believe you can fix this issue in your build without limiting this project to older kotlin versions. Take a look at this solution where the javaagent dependency is managed in an included build (buildSrc) and the subproject uses an old kotlin version but still applies the plugin.

Please let me know if that approach is feasible/fixes the issue in your upstream project

felixscheinost commented 9 months ago

Thank you very much for coming up with that solution, even though I don't completely understand how that makes a difference 😄 Does the resolution of transitive dependencies work differentlly when included in buildSrc compared to when included in plugins block directly?

I haven't had a chance yet to test this in the upstream project but I could reproduce that your solution fixes the problem in my example project.

This issue can probably be closed or do you think there's anything left to do?

ryandens commented 9 months ago

It relies on the fact that the build process and your application can use different Kotlin versions! buildsrc is a different project, so it can configure/compile Kotlin differently. Using buildSrc/included builds to manage build logic and encapsulate/configure external plugins like mine is generally a good idea anyways, so hopefully this helps you work on more incremental improvements for your projects build! Given that Kotlin 1.6.X hasn't received updates since April' 22 I imagine this incompatibility could get worse over time. Just curious - what are the major hurdles for upgrading from kotlin 1.6 -> 1.8 or newer?