How to add a new set with gradle kotlin-dsl

I want to add a set of sources src/gen/java. With groovy, it's quite simple and already described at https://discuss.gradle.org/t/how-to-use-gradle-with-generated-sources/9401/5

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

But I added kotlin-dsl to add a new one. All I have is:

java {
    sourceSets {

    }
}

Can anyone help here

+13
source share
5 answers

You should try the following:

java.sourceSets.create("src/gen/java")

Hope you need it!

+10
source

@ S1m0nw1's answer is correct to add a new set. But to just add a new source folder to an existing set of sources, you can use this:

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

I wanted to add a source set called "test integration" and a source directory src/test-integration/kotlin. I was able to do this by combining two pre-existing answers:

java.sourceSets.create("test-integration").java {
    srcDir("src/test-integration/kotlin")
}
+3
source

I worked on Gradle 4.10.2:

sourceSets.create("integrationTest") {
    java.srcDir("src/integrationTest/java")
    java.srcDir("build/generated/source/apt/integrationTest")
    resources.srcDir("src/integrationTest/resources")
}
+3
source

I worked on Gradle 4.10.2:

sourceSets.getByName("main") {
    java.srcDir("src/main/java")
    java.srcDir("src/main/kotlin")
}
sourceSets.getByName("test") {
    java.srcDir("src/test/java")
    java.srcDir("src/test/kotlin")
}

The above codes can also be used in the block subprojects.

0
source

Source: https://habr.com/ru/post/1686387/


All Articles