How to add new sourceset with gradle kotlin-dsl

guenhter picture guenhter · Sep 26, 2017 · Viewed 16.6k times · Source

I want to add a sourceset src/gen/java. With groovy this is rather easy and already described in https://discuss.gradle.org/t/how-to-use-gradle-with-generated-sources/9401/5

sourceSets {
   gen {
        java.srcDir "src/gen/java"
    }
}

But I stuck with the kotlin-dsl to add a new one. All I've got is:

java {
    sourceSets {

    }
}

Can anyone help here to

Answer

guenhter picture guenhter · Sep 27, 2017

The answer of @s1m0nw1 is correct to add a new sourceset. But to just add a new source-folder in an existing sourceset, this can be used:

java.sourceSets["main"].java {
    srcDir("src/gen/java")
}