Open cloudshiftchris opened 1 year ago
Workaround: run ktfmt directly to avoid mixing class paths:
val ktfmt by configurations.creating
dependencies { ktfmt("com.facebook:ktfmt:0.44") }
val ktfmtFormat by
tasks.registering(JavaExec::class) {
val ktfmtArgs =
mutableListOf("--kotlinlang-style", layout.projectDirectory.asFile.absolutePath)
if (System.getenv()["CI"] != null) ktfmtArgs.add("--set-exit-if-changed")
group = "formatting"
description = "Run ktfmt"
classpath = ktfmt
mainClass.set("com.facebook.ktfmt.cli.Main")
// jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
args(ktfmtArgs)
}
val check = tasks.named("check") { dependsOn(ktfmtFormat) }
tasks.register("precommit") { dependsOn(check) }
Thanks for reporting this
Seems like the plugin could benefit from running ktfmt using either class loader isolation or shaded dependencies to avoid collisions with likely-to-conflict dependencies (the Kotlin setup needed to build an application will frequently differ from the Kotlin setup needed by ktfmt to parse code).
Yup you're right that the ktfmt dependencies will end up contributing to the build dependencies of the whole build. I've been investigating isolating the KtFmt dependencies so that users could effectively specify the tool versions without having a 1:1 relationship between gradle plugin-ktfmt tool.
I'm happy to receive a PR if someone is up for investigating in this space
Will have a look at that, pretty straightforward.
Not having used AGP (and not clear why its a dep on this project) - unable to sync project into IntelliJ after forking due to:
The project is using an incompatible version (AGP 8.1.0) of the Android Gradle plugin. Latest supported version is AGP 8.1.0-dev
Recommended approach to setup dev env?
Not having used AGP (and not clear why its a dep on this project) - unable to sync project into IntelliJ after forking due to:
It compileOnly
dep on AGP as it creates Android tasks if the plugin detects that it's applied to an Android project.
Recommended approach to setup dev env?
IntelliJ IDEA 2023.2 should work without problems. Sadly due to how Android Studio & IntelliJ import the Android plugin source, you always have to be on the latest version of IntelliJ to open the project.
It unfortunately doesn't sync into IntelliJ 2023.2. For the time being I've flipped the dep back to 8.0.2 to get by this.
Something odd here - many of the tests have (by design) invalid Kotlin code, such as this:
@Test
fun `check task skips a file if with --include-only`() {
createTempFile(content = "val answer = `\n", fileName = "File1.kt")
However, in all those places where the invalid content has a backtick, IntelliJ flags them as an error.
Unclear how this could ever have compiled (perhaps it's just an IntelliJ quirk, still working on lots of other things, not able to compile atm).
If we need to replace the backticks presumably all this needs is bad Kotlin of some form.
...because that method parameter is annotation with @Language
it treats the snippet as Kotlin; removed the annotation to avoid the noise (no way to suppress the error).
...because that method parameter is annotation with
@Language
it treats the snippet as Kotlin; removed the annotation to avoid the noise (no way to suppress the error).
Yup that's IntelliJ attempting to render that as Kotlin code and showing errors if they happen to be invalid (fixing them to be valid code would be a nice to fix for the codebase)
Gotcha, thanks. Almost there - working through adjusting tests for use of Worker API (decoupled a lot of code for clarity of isolation / ease of testing).
⚠️ Current behavior
Applying v0.13.0 to a project results in these issues:
Exception compiling Kotlin code when ktfmt plugin applied:
Same exception happens on sync when applying plugin to build-logic (included build w/ convention plugins).
✅ Expected behavior
Applying the ktfmt plugin does not cause exceptions or interfere with other settings.
💣 Steps to reproduce
Install ktfmt plugin via a convention plugin, onto a project using Kotlin 1.8.22 w/ language level 1.9.0.
📷 Screenshots
Dependencies are whacked:
📱 Tech info
Gradle 8.2.1 / Java 19 (same issue with Java 17) / plugin 0.13.0 / Kotlin 1.8.22 (language level 1.9.0)
Seems like the plugin could benefit from running ktfmt using either class loader isolation or shaded dependencies to avoid collisions with likely-to-conflict dependencies (the Kotlin setup needed to build an application will frequently differ from the Kotlin setup needed by ktfmt to parse code).