Skip to content

Convert Custom Test Tasks to Test Suites for Gradle 9 #73

@trask

Description

@trask

Problem

Gradle 9 marks custom Test tasks as "NO-SOURCE" and skips them. Need to migrate ~102 files to modern Test Suites.

Find Files to Fix

grep -r "by registering(Test::" --include="*.kts" .

Migration Pattern

Before:

val testStableSemconv by registering(Test::class) {
  jvmArgs("-Dotel.semconv-stability.opt-in=database")
  systemProperty("collectMetadata", collectMetadata)
}

tasks {
  check {
    dependsOn(testStableSemconv)
  }
}

After:

testing {
  suites {
    val testStableSemconv by registering(JvmTestSuite::class) {
      targets {
        all {
          testTask.configure {
            jvmArgs("-Dotel.semconv-stability.opt-in=database")
            systemProperty("collectMetadata", collectMetadata)
          }
        }
      }
    }
  }
}

tasks {
  check {
    dependsOn(testing.suites.named("testStableSemconv"))
  }
}

Key Changes

  1. by registering(Test::class)by registering(JvmTestSuite::class)
  2. Wrap configs in targets.all.testTask.configure { }
  3. Put test suites inside testing.suites { }
  4. Update dependencies: dependsOn(taskName)dependsOn(testing.suites.named("taskName"))

Validate

./gradlew :module:testStableSemconv --rerun-tasks

Should run tests, not show "NO-SOURCE".

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions