Accessing source sets with kotlin-dsl for gradle

1.9k views Asked by At

How do I convert the following groovy snippet

URL[] urls = sourceSets.main.runtimeClasspath.files.collect {
    it.toURI().toURL()
}

to kotlin-dsl? Particularly the property sourceSets doesn't seem to available and fails to compile.

How do I access the sourceSets in a task?

1

There are 1 answers

5
guenhter On BEST ANSWER

There is no sourceSet for the runtimeClasspath. The classpath is different to the sourceSet. But if you are interested in getting e.g. the main-sourceset of a project with the kotlin-dsl, here is a snippet:

java {
    val files: Set<File> = sourceSets["main"].java.srcDirs
    println(files)
}

Accessing the sourceSet from a task

task("hello-src-set") {
    val files: Set<File> = java.sourceSets["main"].java.srcDirs
    println(files)
}