how can I add dependencies (using Kotlin DSL) to a...
# gradle
k
how can I add dependencies (using Kotlin DSL) to a custom sourceSet? for example, here are my sourceSets:
Copy code
sourceSets {
    main {
        java.srcDir("main")
    }
    test {
        java.srcDir("test")
    }
    create("jmh") {
        java.srcDir("jmh")
    }
}
and the problem is that inside the "jmh" sourceSet I can't import my main classes...
b
kotlin.sourceSets.named("jmh") { dependencies {} }
You can also make one sourceSet depend on the other via dependsOn()
k
what would be the exact syntax in the first case? what goes between {}?
oh, it seems to take
implementation("foo.bar:mproject:0.0.0")
, but then I have to repeat all the dependencies... maybe better to depend on the main sourceSet
how to refer to the main sourceSet inside dependsOn()?
b
You can use raw string as dependant sourceSet name or pass reference to it. Either works
k
Huh, for example this doesn't work:
Copy code
kotlin {
    sourceSets.named("jmh") {
        dependsOn("main")
    }
}
because dependsOn() doesn't take String as argument, it takes a KotlinSourceSet
and I don't know how to get a reference to a main sourceSet 😕
this also doesn't work:
dependsOn(sourceSets.named("main"))
b
You can use sourceSets.findByName then
k
At least it's not a type error anymore 🙂, but still this
Copy code
kotlin {
    sourceSets.named("jmh") {
        dependsOn(sourceSets.findByName("main")!!)
    }
}
doesn't work, running the benchmarks fails with:
Copy code
Project#afterEvaluate(Action) on root project 'myproject' cannot be executed in the current context.
I think I'm gonna scrap this for now, and just copy paste everything... this Gradle thing is more confusing than trying to prove theorems in Idris 😄
Thanks for the help!
I get that I have to somehow point one sourceSet to another, but why arent dependencies declared in the global dependencies {} block really global?