Gradle question, I think <@U01681FLZC2> might be t...
# kotest-contributors
s
Gradle question, I think @Adam S might be the best person to answer. Inside a gradle plugin task, how do I get the source sets? Specifically, I am trying to get a handle to the "test" sourceset. At the moment I am looking for the JavaPluginExtension, and getting it from that, but this fails for android. Follow up question - when you have a layout like say
src/main/java
and
src/main/kotlin
and
src/main/scala
is "main" the sourceset, or is java kotlin scala the sourcesets?
e
They're available through the Kotlin extension.
Copy code
// Configure Kotlin multiplatform projects
      project.pluginManager.withPlugin(KOTLIN_MULTIPLATFORM_PLUGIN) {
         project.extensions.configure<KotlinMultiplatformExtension> {
            sourceSets.filter { it.name.contains("test", ignoreCase = true) }
java, kotlin and scala would be the soucesets in your example was wrong.. oops 🙈
s
is multiplatform there for android ?
e
Isn't Android just a regular JVM target?
a
try taking a look at how Dokka Gradle plugin gets the source sets JavaAdapter.kt is much more simple than KotlinAdapter.kt, but the principle should be the same
the KotlinAdapter does a bunch of confusing stuff to be Configuration Cache compliant, but what Emil wrote is basically the same
when you have a layout like say src/main/java and src/main/kotlin and src/main/scala is "main" the sourceset, or is java kotlin scala the sourcesets
a
org.gradle.api.tasks.SourceSet
is either main or test (or something else, because users can add their own custom SourceSets), and each SourceSet has 1+ source directories like
src/main/kotlin
l
Android is a really weird JVM target. But yes, anything compiled to JVM should work on Android
@sam Yes, MPP is there for Android. People develop apps having Common + IOS/Android and split the artifact for both platforms
We don't need to fully support MPP for it yet, as we don't really support Android officially. JVM versions should be fine as long as the JDK version is compatible (use 8 and you're find. Above this I'm not 100% sure)
s
This has been helpful. I'm still stuck though. So I can get the
Copy code
KotlinProjectExtension
and in there find the test sourceset. But this returns a
KotlinSourceSet
not a
SourceSet
. The regular
SourceSet
type that comes from the
JavaBasePlugin
has a
runtimeClasspath
option which is a file tree of all the compiled files. Trying to find the same thing but for Android projects.
Ok so I have it working for android. But it's hacky, I have to add this "tmp kotlin classes folder" to the runtime classpath manually.
Copy code
val classesDir = project.layout.buildDirectory.get().asFile.toPath().resolve("tmp/kotlin-classes/releaseUnitTest")
val runtimeClasspath = project.configurations["releaseUnitTestRuntimeClasspath"]
val classpathWithTests = runtimeClasspath.plus(fileCollectionFactory.fixed(classesDir.toFile()))
I wonder if there's a way to make not use hard coded strings