-
Notifications
You must be signed in to change notification settings - Fork 503
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
ktlint fails on Java 16+ #1195
Comments
Are you using cli or a gradle plugin? For me, this looks like you are using either an older version of ktlint or having an older version of Kotlin (< 1.5.0), which substitutes ktlint's Kotlin version, because the issue has been resolved in Kotlin 1.5.0-M2 it looks like (and we are targeting 1.5.20 in the latest release) |
To me this happens with the CLI version. |
I am using ktlint with Gradle wrapper (without a plugin) with Gradle 7.1.1 when running ./gradlew ktlintFormat:
|
I have the same version combination and the same failure happens. |
hm, probably we also need to add |
You could try to run KtLint with |
It seems to work for me after adding this line as stated in the new readme for 0.42.1:
Edit: Not working again now
|
Android Studio Arctic Fox with java 11、the same problem. |
Any news about this? |
@cuichanghao could you make sure everything is setup correctly? java 11 should work fine, I'm using Java 11 right now due to this issue |
For maven projects using the
|
happens to us too |
same here |
@Tapchicoma @shashachu @shyiko any timeline on fixing this? |
I am currently trying to fix it myself. I cloned the repo and built a jar with Java 17 on my own machine. I ran it with the following configuration, which seems to work:
All tests passed, 3 were skipped. |
For those using the Gradle Kotlin DSL, I was able to invoke the formatter without issues with JDK 17 by doing the following: tasks.register<JavaExec>("ktlintFormat") {
group = "formatting"
description = "Fix Kotlin code style deviations"
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
args("-F", "src/**/*.kt")
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
} The most important part here is adding: jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") |
Have the same configuration. Added the extra jvmArgs. It runs through the code, corrects what needs corrected, leaves comments on being unable to fix Wildcards (why is that?), but ends with the same error again:
|
Wildcards are never fixed automatically afaik |
I think this bug is still not fixed. In case the linter has to fix some linting issues there is still an exception
|
Has anyone gotten the flags to work using bazel? |
0.46.1 still not working |
I'm seeing the same error with gradle 7.5 and ktlint 0.46.1 |
This is not related to Java 16. The class mentioned above has been removed in ktlint 0.46. |
Java 17-temurin mvn ktlint:format -DjvmArgs="--add-opens java.base/java.lang=ALL-UNNAMED" -DjvmArgs=" --add-exports java.base/sun.nio.ch=ALL-UNNAMED" Error: |
Please check whether any of workarounds mentioned in https://youtrack.jetbrains.com/issue/KT-43704 |
See pinterest/ktlint#1195 and ScoopInstaller/Extras#10313. Note that although this should have been fixed in the latest version of ktlint (we are using an old one), the fix doesn't seems to have worked for me.
It worked for me by adding the following line to |
See pinterest/ktlint#1195 and ScoopInstaller/Extras#10313. Note that although this should have been fixed in the latest version of ktlint (we are using an old one), the fix doesn't seems to have worked for me.
Still fails for me on ktlint version 0.50.0 Everything works with ktlint version 0.40.0 |
Hmmm, you are updating 10 versions in one go and expect everything to work out of the box? You could try to read the changelog or search for documentation or issues. https://pinterest.github.io/ktlint/1.0.0/install/integrations/ |
see this fix in ktlint issue tracker pinterest/ktlint#1195 (comment)
The text was updated successfully, but these errors were encountered: