Hey all :wave: Sharing a small Gradle :gradle: pl...
# feed
g
Hey all 👋 Sharing a small Gradle G plugin I wrote recently that lets you run #ktfmt on your project without having to download the CLI or setup an IntelliJ Plugin: https://github.com/cortinico/ktfmt-gradle/
👍 1
💪 3
🔝 3
🎉 2
y
If we are using spotless for ktfmt is there any differences making it compelling to switch?
g
That plugin exposes a couple of fields that I believe spotless is not exposing. Other than that, no major reasons.
👍 1
r
Sorry for newbie question here. In all my projects I get this error:
Copy code
Execution failed for task ':core:ktfmtFormatMainJavaSource'.
> 132:46: error: did not generate token ";"
What am I doing wrong?
g
Sorry for newbie question here.
You should not be sorry for asking 🙏 Seems like a bug, potentially in #ktfmt rather than the gradle plugin 🧐 Could you open an issue (if you could also provide the file where it’s failing that would be awesome)
r
I can't provide the whole file as it isn't my personal project. How can I find which file the error is referring to though? (File: 132? Line: 46?).
g
If you rerun with
--info
the tool prints out what is doing.
r
It doesn't show more info than that. With `--info`:
Copy code
> Task :core:ktfmtFormatMainJavaSource
Caching disabled for task ':core:ktfmtFormatMainJavaSource' because:
  Build cache is disabled
Task ':core:ktfmtFormatMainJavaSource' is not up-to-date because:
  Task has failed previously.

> Task :core:ktfmtFormatMainJavaSource FAILED
:core:ktfmtFormatMainJavaSource (Thread[Daemon worker,5,main]) completed. Took 12.826 secs.

Execution failed for task ':core:ktfmtFormatMainJavaSource'.
> 132:46: error: did not generate token ";"
With `--stacktrace`: https://pastebin.com/Jk3hHk50
I tried spotless and it did return a better error.
Copy code
Step 'ktfmt' found problem in 'app\src\main\java\-someting-\main\fragment\home\account\cards\CardAdapter.kt':
32:45: error: did not generate token ";"
So it turns out, it can't handle a
;
in a when, for example (changed names):
Copy code
icon.setImageResource(when (issuerID) {
                "Something1" -> something1; "Something2" -> somethings2
                "" -> something3.also { \* some other code in here *\ }
                else -> something4
            })
g
Oh that’s interesting 👀 thanks for investigating
Just a couple of follow ups: • I’ve reported the
;
issue upstream here. That needs to be addressed by ktfmt maintainers. • I’ve fixed the error message as when ktfmt was crashing, the gradle plugin was not reporting on which file failed. That’s merged here
r
Awesome!
🙏 1
c
ktfmt 0.22 is now out, fixing the semicolon issue.
👍🏼 1
g
I’ve also update the plugin to ship this fix: https://github.com/cortinico/ktfmt-gradle/releases/tag/0.5.0
❤️ 2