for tasks named based on a source set, like `check...
# community-support
c
for tasks named based on a source set, like
checkstyleMain
is there an easy way to reverse that to just the source set name? it'd be convenient to reduce this code given feature variants and test suites
Copy code
tasks.named<Checkstyle>("checkstyleMain") {
  configFile = checkstyleConfig("main.xml")
}
I guess this works, but seems hacky
Copy code
tasks.withType<Checkstyle>().configureEach {
  this.name.substringAfter("checkstyle").replaceFirstChar { it.lowercase() }.let { filename ->
    logger.quiet("checkstyleConfig: $filename")
    configFile = checkstyleConfig("${filename}.xml")
  }
}
t
How about going the other way: from source set to task?
Copy code
sourceSets.configureEach {
  tasks.named<CheckStyle>(getTaskName("checkstyle", null)) {
    // …
  }
}
That being said, your approach is also used by code quality plugins: https://github.com/gradle/gradle/blob/057b55410a1b8cb3161ab9c7d4a8a34937f944ac/pla[…]dle/api/plugins/quality/internal/AbstractCodeQualityPlugin.java
👍 1