After upgrading to Gradle 6.x sometime ago I start...
# gradle
l
After upgrading to Gradle 6.x sometime ago I started to notice that after each and every build of my Kotlin project, Gradle generates Java source folders _unnecessarily_: •
src/main/java
src/test/java
My current configuration is:
Copy code
$ ./gradlew -v
------------------------------------------------------------
Gradle 6.5.1
------------------------------------------------------------

Build time:   2020-06-30 06:32:47 UTC
Revision:     66bc713f7169626a7f0134bf452abde51550ea0a

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.8 (<http://Amazon.com|Amazon.com> Inc. 11.0.8+10-LTS)
OS:           Linux 5.4.0-42-generic amd64
I added the following to my
build.gradle.kts
script but had no effect whatsoever:
Copy code
sourceSets {
    main {
        java.srcDir("src/main/kotlin")
        resources.srcDir("src/main/resources")
    }
    test {
        java.srcDir("src/test/kotlin")
        resources.srcDir("src/test/resources")
    }
}
o
afaik Gradle itself and the Kotlin plugin never create source directories
yea, just tested -- cannot reproduce with 6.5.1 and Kotlin 1.3.72
l
After you mentioned, I started enabling/disabling Gradle plugins until I found the culprit:
ktlintFormat
😢
Now I just need to figure out what rule is causing..
I am using
ktlint
9.3.0
After further investigation, I can confirm the issue is at least partly related to Gradle.. said regression occurred while upgrading from version 6.1.1 to 6.2 of Gradle. Before 6.2 the issue does not occur regardless of what version of the ktlint plugin I set (up to the latest version 9.3.0)
m
You can use setSrcDirs with a list of directories instead of srcDir. The former will overwrite all existing source directory settings while the latter will only add some to the existing settings.
l
Thx Marc. that is a workaround..