Skip to content

testScoverage task's source property is incorrect #78

Closed
@dsilvasc

Description

@dsilvasc

The testScoverage task gets skipped with "NO-SOURCE" if you skip the compileTestScala task.

People might want to skip the compileTestScala and test tasks when they're already running compileTestScoverageScala and testScoverage, to avoid compiling and running tests twice.

I'm using this as a workaround for now:

// the testScoverage task already runs all the tests;
// no need to run them twice
// https://stackoverflow.com/questions/30512237/configuring-a-gradle-task-based-on-task-to-be-executed
gradle.taskGraph.whenReady {
  val test by tasks
  val compileTestScala by tasks
  val compileTestScoverageScala by tasks
  if (hasTask(testScoverage)) {
    test.enabled = false
  }
  if (hasTask(compileTestScoverageScala)) {
    compileTestScala.enabled = false
    // Since we won't run compileTestScala, change the test source set's output
    // to the output dir of compileTestScoverageScala.
    // Otherwise the task testScoverage will be skipped with "NO-SOURCE".
    val testSourceSet = project.the<JavaPluginConvention>().sourceSets.getByName("test")
    // need to use withGroovyBuilder because of this issue:
    // // https://github.com/gradle/kotlin-dsl/issues/650
    testSourceSet.withGroovyBuilder {
      "scala" {
        "setOutputDir"(project.file("${project.buildDir}/classes/scala/testScoverage"))
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions