ktlint-gradle
ktlint-gradle copied to clipboard
src/main/kotlin not working out of the box
As of Android Studio Arctic Fox and Android Gradle Plugin 7.0, we do not need to specify the source directories for java:
https://stackoverflow.com/questions/41467453/renaming-java-directory-to-kotlin-in-android-studio
You should also support this out of the box for ktlint.
Sorry, I don't get what is the issue? Plugin does not do such renaming and should not do.
Experiencing a similar issue when using AGP 7.0 and 10.1.0 version of this plugin. It looks like AGP introduced another source set called kotlin which includes both src/main/kotlin and src/main/java. src/main/kotlin is not included in the java source set though.
If understand it correctly, this plugin only looks at the java source set at the moment:
https://github.com/JLLeitschuh/ktlint-gradle/blob/d945407634b788bc0968962bad7da00aaeb4ae20/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/android/AndroidPluginsApplier.kt#L72
Workaround for now is to add Kotlin directories to java source set (or keep the sources in src/main/java):
android.sourceSets.configureEach {
java.srcDirs("src/$name/kotlin")
}
Experiencing a similar issue when using AGP 7.0 and 10.1.0 version of this plugin. It looks like AGP introduced another source set called
kotlinwhich includes bothsrc/main/kotlinandsrc/main/java.src/main/kotlinis not included in thejavasource set though.If understand it correctly, this plugin only looks at the
javasource set at the moment: https://github.com/JLLeitschuh/ktlint-gradle/blob/d945407634b788bc0968962bad7da00aaeb4ae20/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/android/AndroidPluginsApplier.kt#L72Workaround for now is to add Kotlin directories to
javasource set (or keep the sources insrc/main/java):android.sourceSets.configureEach { java.srcDirs("src/$name/kotlin") }
Thanks for explaining what my issue is.
Maybe we should support the "src/$name/kotlin" by default ?
The kotlinter plugin fixed this issue in this PR https://github.com/jeremymailen/kotlinter-gradle/pull/229
Should this ktlint plugin fix the issue too?
PRs are welcome to resolve this issue, please do include test coverage.
What do we intend to do about this issue? I see that the PR #558 has no movement for 2+ months now.
If this is something that is not going to be addressed soon or isn't being actively worked on at this moment, I'd really like to see it in the readme. I've unfortunately wasted way too much time thinking my setup was wrong and the fix was to simply rename the dir from kotlin to java. I am sure that there's more people out there who have also come across this bug unfortunately. Would you accept a contribution to the README if I were to write a sentence about this bug until it's resolved?
PRs are welcome to address this problem. Please see the pinned comment regarding the current maintenance status of this project
Right, I was referring to merging a PR with some explanatory text, perhaps as an entry to the FAQ which would mention that you need to name the file java and that kotlin doesn't work.
As far as solving the problem itself there seems to have been some work here https://github.com/JLLeitschuh/ktlint-gradle/pull/558 but no activity lately. Definitely not familiar enough with fixing something like that to tackle it myself.
This should be fixed by #733.