Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new sourceset with gradle kotlin-dsl

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

like image 932
guenhter Avatar asked Sep 26 '17 07:09

guenhter


People also ask

What is the Kotlin Gradle DSL?

Gradle's Kotlin DSL provides an alternative syntax to the traditional Groovy DSL with an enhanced editing experience in supported IDEs, with superior content assist, refactoring, documentation, and more.

How do I add dependency to Kotlin?

Adding Android dependencies The workflow for adding Android-specific dependencies to a Kotlin Multiplatform module is the same as it is for pure Android projects: declare the dependency in your Gradle file and import the project. After that, you can use this dependency in your Kotlin code.

What is DSL in Gradle?

Simply, it stands for 'Domain Specific Language'. IMO, in gradle context, DSL gives you a gradle specific way to form your build scripts. More precisely, it's a plugin-based build system that defines a way of setting up your build script using (mainly) building blocks defined in various plugins.

What does SourceSet do in Gradle?

1.1 What is a Gradle SourceSet ? A SourceSet is a collection of java source files and additional resource files that are compiled and assembled together to be executed. The main idea of sourcesets is to group files with a common meaning for the project, with no need of separate them in another project.


1 Answers

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") } 
like image 57
guenhter Avatar answered Sep 28 '22 01:09

guenhter