How to add new sourceset with gradle kotlin-dsl

后端 未结 5 1927
死守一世寂寞
死守一世寂寞 2021-02-07 04:55

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-sourc

相关标签:
5条回答
  • 2021-02-07 05:19

    I wanted to add a source set with the name "test-integration" and the source directory src/test-integration/kotlin. I was able to accomplish that by combining the two pre-existing answers:

    java.sourceSets.create("test-integration").java {
        srcDir("src/test-integration/kotlin")
    }
    
    0 讨论(0)
  • 2021-02-07 05:21

    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")
    }
    
    0 讨论(0)
  • 2021-02-07 05:21

    Worked for me 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 codes above can also be used in subprojects block.

    0 讨论(0)
  • 2021-02-07 05:27

    Worked for me 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")
    }
    
    0 讨论(0)
  • 2021-02-07 05:33

    You should try the following:

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

    Hope it's what you need!

    0 讨论(0)
提交回复
热议问题