- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 794
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
JVM 17 & Kotlin 1.6.x Support #4786
Comments
Could you link to the revert you're talking about? |
@cortinico this is the ticket he's referring to that should have fixed it, but it is no longer working. #4277 |
This hasn't been reverted though 🤔 I'm wondering if @Nitewriter was referring to a specific revert or not |
Is there a workaround, or do we need to revert to 1.19 for now? |
How are you folks passing the |
In my case I'm using the gradle plugin. I am not passing that argument explicitly at all. |
I'm not able to reproduce. Tested with:
Running |
Seems like the problem might be this declaration in my Gradle build:
It also doesn't seem to matter which version is actually specified -- detekt bails in any case. |
That should work. Could you try with just "11" or with |
The output of |
Thanks for the hint @cortinico on Looking at the code at https://github.com/detekt/detekt/blob/main/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/ArgumentConverters.kt#L54-L57, it looks like this code assumes that I now see also in the README at https://github.com/detekt/detekt#with-gradle it does actually specify that the jvm target needs to be set explicitly for Detekt -- this appears to be new in 1.20 and was not called out in the migration guide at all. I'm wondering if the plugin can simply use the JVM target from the Kotlin compiler options rather than having to inject this value separately. |
Thanks for looking into this @rocketraman detekt/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgs.kt Lines 189 to 195 in 16bbc16
|
I assumed when I wrote my previous message that adding the explicit Debugging further, I think I see the problem... the |
The failure seems to be at this line:
in the |
More specifically, This fails because
|
I submitted a PR #4800 to hopefully fix this. I haven't tested this TBH but it does compile. |
I've added some new tests in #4801. Strings are mapped from Gradle plugin and parsed correctly by the CLI. I'm not sure what I'm missing here, so a full reproducer will be helpful, but I will continue investigating in the meantime. |
What could be the problem is if It should work if you just set |
I was on Gradle 7.3.3. I updated to 7.4.2 to check if that was the issue. Same problem with both versions. There should be no change in the version of Kotlin on the classpath -- I have no local customizations in this regard. Gradle uses whatever it uses, my build uses 1.6.10.
No this does not work. In fact, I've never had I'm not sure why all of these conversions from JvmTarget to and from Strings are going on. If you look at PR #4800 I submitted earlier, eventually you need to pass a |
Please provide a reproducer and we can hopefully narrow down exactly what's going on. |
* Add CLI tests to ensure jvm-target and language-version flags are properly mapped * Make errors while mapping jvm-target & language-version inputs more descriptive * Return IAE instead of ISE when jvm-target & language-version fails to parse * Add tests ensuring jvmTarget & languageVersion are mapped to CLI flags
A build scan may also help. |
If you saw an earlier email from me due to a comment on this issue, please ignore it -- I thought I had created a reproducer but it was a silly mistake on my part. So far I'm not having any luck with the reproducer. I'll continue trying to reproduce for a bit, but I'm not sure how much longer I can spend on this. I'm happy to jump on a meeting to debug this together. |
I finally reproduced it... here is the repro repository: https://github.com/rocketraman/test-detekt-4786. Looks like this particular block in my gradle build is the source of the problem: https://github.com/rocketraman/test-detekt-4786/blob/master/build.gradle.kts#L13-L21. I normally do this in my builds to ensure that my chosen version of Kotlin is used everywhere in my build. |
It looks like that block is pulling in the 1.6.10 version of kotlin-compiler-embeddable whereas detekt is expecting the 1.6.20 version. Build scan with invalid target, showing the kotlin-compiler-embeddable dependency: and same with the working detekt: |
That's exactly what's happening - detekt uses the "detekt" configuration to manage the Gradle plugin's dependencies, which would normally be pulling in detekt-cli 1.20.0 and kotlin-compiler-embeddable 1.6.20 (or 1.6.21, can't recall which we shipped with). When you override all configurations you're also overriding the "detekt" configuration, overriding the expected kotlin-compiler-embeddable version. You can do this instead: I've tested on your repo and it fixes the issue. |
@Nitewriter I'm conscious that you might have a different root cause - or is this enough info to resolve your issue as well? |
Is it correct for detekt to be tied so strongly to a particular kotlin version? And even if yes, then should detekt fail in such an esoteric way if that constraint is not met? |
Yes. detekt utilises internal compiler code for its analysis. There's no public API as such so we don't have much choice here. Some updates to Kotlin are breaking for detekt so maintaining compatibility with multiple Kotlin versions isn't realistic.
I think that's debateable. In your case it's a build configuration issue, and we can't account for everything that someone might do in their own build files when they inadvertently override the behaviour of the detekt Gradle plugin. We can't lock the specific Kotlin compiler version in the Gradle plugin either, because users can choose different detekt-cli versions and apply to the "detekt" configuration. A warning might be feasible, PR welcome. |
There is no need to account for "everything that someone might do". There should be a need to account for fundamental constraints of detekt being violated and warn or error on that accordingly.
If this statement is true (it may be, but not really in this case -- the error condition in question was not anything fundamental with the compiler here, but rather the code relying on a specific version's behavior related to an ancillary function like "Detekt requires Kotlin compiler version 1.6.20 for analysis. Detekt is currently running with Kotlin compiler version x.x.x. Check the Detekt configuration." instead of a message like: "Invalid --jvm-target value"
I've spent way more time on this issue already than I can justify -- might as well spend a bit more :-) Maybe I'll get to this. Pointers/guidance welcome. |
BTW, other libraries that depend on specific compiler versions, like Compose, have just such logic in them. Compose will fail in the presence of the wrong Kotlin version, unless a specific setting is used to override that check. Furthermore, IIRC Compose uses the version of Kotlin in the project and requires that to match the version expected by Compose -- it doesn't try to bring in its own version and use that, regardless of the version selected by the user. It seems the approach of selecting a compiler version which may not match the user's selected version is likely to cause other problems. |
I'm using JDK11, detekt 1.20.0 and kotlin 1.6.10 and all works perfect so this is a bit more complex. I mean, detekt right now works on other versions of kotlin too. |
See #4786 (comment) We have the root cause and a fix for that issue, but I'm not sure if the original reporter has a different issue. |
@3flex Thanks |
@itd-pal I think that would be better raised in a separate support request, thanks! Try https://github.com/detekt/detekt/discussions |
Workaround as per detekt/detekt#4786 (comment)
Should we close this issue then? |
This effectively pins the Kotlin compiler version used by detekt-cli, minimising the chance of it being overridden and causing issues such as detekt#4786
FYI |
This effectively pins the Kotlin compiler version used by detekt-cli, minimising the chance of it being overridden and causing issues such as #4786
The changes made to the final version of 1.20.0 have reverted fixes that addressed the
invalid jvm target
error experienced in this ticket. #4287I'm currently unable to upgrade to resolve the current
XML External Entity (XXE) Injection
vulnerability. Version 1.20.0-RC2 continues to have no issues with JVM 17 and Kotlin 1.6.x, but does not have a resolution for the vulnerability.The text was updated successfully, but these errors were encountered: