2

In Gradle (Groovy), I used to do this to configure source sets:

build.gradle:

apply plugin: 'java'
apply from: 'gradle/test.gradle'

gradle/test.gradle:

sourceSets {
    unitTest {
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
}

And then I'd use the unitTest source set for creating tasks.

When I try to do the same in IntelliJ for Gradle KTS:

build.gradle.kts:

plugins {
    java
}

apply(from = "gradle/test.gradle.kts")

gradle/test.gradle.kts:

sourceSets {
    create("unitTest") {
     // Do configurations
    }
}

If fails with a Unresolved reference: sourceSets error.

How can I this same thing in Kotlin Gradle?

LeoColman
  • 6,950
  • 7
  • 34
  • 63
  • It does find the file. The Unresolved Reference is when it's trying to "compile" `gradle/test.gradle`. This exact code in Groovy works. – LeoColman Jan 23 '19 at 15:36
  • If I try to rename the file, the error is different (file not found of some sort) – LeoColman Jan 23 '19 at 15:37
  • Possible duplicate of [Unresolved reference: sourceSets for Gradle Kotlin DSL](https://stackoverflow.com/questions/52975515/unresolved-reference-sourcesets-for-gradle-kotlin-dsl) – sschuberth May 20 '19 at 07:56

1 Answers1

0

Its kind of duplication of Unresolved reference: sourceSets for Gradle Kotlin DSL

You can't reference sourceSet directly when using separate gradle file. From referenced answer:

Since the plugin is applied imperatively in the same build script, Gradle can't know the plugin is applied and thus can't generate the extension functions allowing to access the source sets.

As mentioned, you can use project.the<SourceSetContainer>()

To create new sourceSet create() method can be used.

project.the<SourceSetContainer>().create("unitTest")

Raino Kolk
  • 81
  • 1
  • 4