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

Compatibility with Kotlin 2.x #618

Open
Hyunk3l opened this issue Dec 6, 2024 — with Slack · 6 comments
Open

Compatibility with Kotlin 2.x #618

Hyunk3l opened this issue Dec 6, 2024 — with Slack · 6 comments
Labels
bug Something isn't working dependencies Pull requests that update a dependency file enhancement New feature or request

Comments

Copy link

Hyunk3l commented Dec 6, 2024

hei team

I'm trying to use rewriteRunhttps://github.com/Hyunk3l/ecommerce in this public project I've (kotlin 2.1, java 17, etc.)

rewrite {
    activeRecipe(
        "org.openrewrite.java.OrderImports",
    )
}

I'm trying with this recipe and this is the error I get

'org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope org.jetbrains.kotlin.cli.jvm.compiler.VfsBasedProjectEnvironment.getSearchScopeByPsiFiles(java.lang.Iterable, boolean)'

I suspect it's because of Kotlin 2.1.. so I downgraded it to 2.0.20 but

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shopping:rewriteRun'.
> 'org.jetbrains.kotlin.fir.FirSession org.jetbrains.kotlin.fir.session.FirSessionFactoryHelper.createSessionWithDependencies(org.jetbrains.kotlin.name.Name, org.jetbrains.kotlin.platform.TargetPlatform, org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices, org.jetbrains.kotlin.fir.java.FirProjectSessionProvider, org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment, org.jetbrains.kotlin.config.LanguageVersionSettings, org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope, org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope, org.jetbrains.kotlin.incremental.components.LookupTracker, org.jetbrains.kotlin.incremental.components.EnumWhenTracker, org.jetbrains.kotlin.incremental.components.ImportTracker, org.jetbrains.kotlin.fir.session.IncrementalCompilationContext, java.util.List, boolean, kotlin.jvm.functions.Function1, kotlin.jvm.functions.Function1)'

Slack Message

@Hyunk3l
Copy link
Author

Hyunk3l commented Dec 6, 2024

BTW, I'm using Kotlin 1.9.22 now and it's working correctly

@timtebeek timtebeek added bug Something isn't working enhancement New feature or request dependencies Pull requests that update a dependency file labels Dec 7, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Dec 7, 2024
@timtebeek
Copy link
Contributor

Thanks for logging the issue and posting the workaround! As also indicated via Slack definitely something to look into, with help appreciated. I imagine we'll want to support both K1 and K2, so that's be interesting.

@pettermahlen
Copy link

pettermahlen commented Dec 12, 2024

I'm running into similar issues when using Kotlin 1.9.24 - unfortunately, it's not realistic to couple the repo's Kotlin version to the one that openrewrite-kotlin is using. I think that, probably, openrewrite-kotlin could shade its version of the embeddable Kotlin compiler, so that it can use a different one to parse Kotlin code than the one that is used when building. The concrete issue I'm seeing is

'org.jetbrains.kotlin.fir.FirSession org.jetbrains.kotlin.fir.session.FirSessionFactoryHelper.createSessionWithDependencies(org.jetbrains.kotlin.name.Name, org.jetbrains.kotlin.platform.TargetPlatform, org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices, org.jetbrains.kotlin.fir.java.FirProjectSessionProvider, org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment, org.jetbrains.kotlin.config.LanguageVersionSettings, org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope, org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope, org.jetbrains.kotlin.incremental.components.LookupTracker, org.jetbrains.kotlin.incremental.components.EnumWhenTracker, org.jetbrains.kotlin.incremental.components.ImportTracker, org.jetbrains.kotlin.fir.session.IncrementalCompilationContext, java.util.List, boolean, kotlin.jvm.functions.Function1, kotlin.jvm.functions.Function1)'
java.lang.NoSuchMethodError: 
	at org.openrewrite.kotlin.KotlinParser.parse(KotlinParser.java:461)
	at org.openrewrite.kotlin.KotlinParser.parseInputs(KotlinParser.java:171)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:282)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:132)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:127)

@timtebeek
Copy link
Contributor

Thanks for the report @pettermahlen ; Surprised to see that's even an issue with the v1.9.22 we're using:

val kotlinVersion = "1.9.22"

Feel free to bump that up to 1.9.24 if that helps you there already; then we can tackle the v2 migration later.

@pettermahlen
Copy link

The main point I was trying to make is that it's not ideal for rewrite-kotlin to require users to use a specific version of Kotlin when building their source. Instead, since rewrite-kotlin uses internal APIs that change even with minor bumps, it should be shading those. That way, openrewrite-kotlin's upgrades of the compiler APIs it's using for parsing, and each of the projects upgrades of the version used to build with can be kept separate.

It seems like it would be very awkward if the latest version of kotlin-rewrite always only worked with the latest version of Kotlin.

@timtebeek
Copy link
Contributor

timtebeek commented Dec 13, 2024

Oh that I fully understand and agree with; my expectation though is that the 1.9 branch will not evolve much anymore, so for now ensuring we are compatible with the now-latest v1.9.25 would mean at least folks on 1.9 can continue to use rewrite-kotlin. v2 would be a larger effort which we can then tackle separately.

timtebeek added a commit that referenced this issue Dec 13, 2024
As discussed on #618
timtebeek added a commit that referenced this issue Dec 13, 2024
As discussed on #618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

3 participants