ktlint-gradle icon indicating copy to clipboard operation
ktlint-gradle copied to clipboard

src/main/kotlin not working out of the box

Open VincentJoshuaET opened this issue 4 years ago • 11 comments

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.

VincentJoshuaET avatar Sep 01 '21 07:09 VincentJoshuaET

Sorry, I don't get what is the issue? Plugin does not do such renaming and should not do.

Tapchicoma avatar Sep 07 '21 20:09 Tapchicoma

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")
}

drymarau avatar Sep 08 '21 09:09 drymarau

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")
}

Thanks for explaining what my issue is.

VincentJoshuaET avatar Sep 08 '21 23:09 VincentJoshuaET

Maybe we should support the "src/$name/kotlin" by default ?

Goooler avatar Dec 15 '21 03:12 Goooler

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?

eduardbosch avatar Dec 21 '21 10:12 eduardbosch

PRs are welcome to resolve this issue, please do include test coverage.

JLLeitschuh avatar Dec 21 '21 21:12 JLLeitschuh

What do we intend to do about this issue? I see that the PR #558 has no movement for 2+ months now.

saran2020 avatar Mar 31 '22 20:03 saran2020

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?

StylianosGakis avatar Jul 05 '22 16:07 StylianosGakis

PRs are welcome to address this problem. Please see the pinned comment regarding the current maintenance status of this project

JLLeitschuh avatar Jul 09 '22 15:07 JLLeitschuh

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.

StylianosGakis avatar Aug 15 '22 22:08 StylianosGakis

This should be fixed by #733.

Goooler avatar Jan 20 '24 10:01 Goooler