Michael Marshall
10/14/2021, 12:13 AMdetekt, detektMain and then detektTest so we get type resolution running across both main and test source sets. However when we do this the report files seem to overwrite each other, and only one is left at the end (seems to be a random one). Any idea how we can keep all the report files - or merge them as we go along?ephemient
10/14/2021, 12:25 AMtasks.withType<Detekt>().configureEach {
reportsDir.set(layout.buildDirectory.dir("reports/$name").map { it.asFile })
}
but it does feel like this should be handled automatically…Michael Marshall
10/14/2021, 12:27 AMdetekt does, and that handled reporting properly. Thanks I’ll try that!gammax
10/14/2021, 12:27 AMreports{} block? We merged a change that is addressing this and will be shipped in the upcoming releasegammax
10/14/2021, 12:28 AMdetewtWithTypeResolution was also an idea we had some times ago. I believe we should go for it as more and more users get to start using type resolutionMichael Marshall
10/14/2021, 12:48 AMreports {
xml {
enabled = true
destination = file("${project.buildDir}/reports/detekt/detekt.xml")
}
html {
enabled = true
}
txt {
enabled = false
}
sarif {
enabled = false
}
}Michael Marshall
10/14/2021, 12:50 AMdetekt if I’m also doing detektMain and detektTest? I don’t need to run detekt on debug/releasegammax
10/14/2021, 9:44 AMYes I’ve got my block set up like thisYeah the problem is that that
destination is used by all the Gradle task. So you’re effectively telling all of your tasks to write in the same file ¯\_(ツ)_/¯ That’s a bug in the design of the Gradle extention and we deprecated it.gammax
10/14/2021, 9:45 AMDo I need to runNot really.if I’m also doingdetektanddetektMain?detektTest
Michael Marshall
10/15/2021, 3:51 AMdestination field deprecated or the whole reports block? I can’t see any deprecation warnings in the source codeMichael Marshall
10/15/2021, 4:21 AMMichael Marshall
10/15/2021, 5:24 AMdetektTest. I’m now trying this
tasks.withType<io.gitlab.arturbosch.detekt.Detekt> {
reports {
xml.enabled = true
xml.destination = file("${project.buildDir}/reports/detekt/$name.xml")
html.enabled = true
html.destination = file("${project.buildDir}/reports/detekt/$name.html")
txt.enabled = false
sarif.enabled = false
}
}
but the name appears to just be detekt no matter whether I run detektMain , detektTest or detekt - so my report file still gets overriden 😢ephemient
10/15/2021, 6:53 AMMichael Marshall
10/15/2021, 6:54 AMdetektMain and detektTest aside from the name? If I can do that I can work around it with the above codeephemient
10/15/2021, 7:28 AMreports with the same extension.reports instance
• detekt gradle plugin configures each report to have default "${sourceSet.name}.extension", which normally isn't noticed due to the above, but is exposed when we start changing reports ourselvesephemient
10/15/2021, 7:29 AMafterEvaluate {
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
reports = io.gitlab.arturbosch.detekt.extensions.DetektReports().apply {
xml.destination = file("build/reports/detekt/${this@configureEach.name}.xml")
html.destination = file("build/reports/detekt/${this@configureEach.name}.html")
txt.destination = file("build/reports/detekt/${this@configureEach.name}.txt")
sarif.destination = file("build/reports/detekt/${this@configureEach.name}.sarif")
}
}
}Michael Marshall
10/15/2021, 7:42 AMfile("${project.buildDir}/reports/detekt/${this@configureEach.name}.xml")
since for some reason they won’t appear in the build file otherwise.
Even with that the output file names are random, since I guess the order in which the tasks are completed isn’t consistent?ephemient
10/15/2021, 7:44 AMsubprojects {} block or something? given the previous issues I don't know if that can be done reliablyMichael Marshall
10/15/2021, 7:45 AMbuild.gradle.ktsephemient
10/15/2021, 7:46 AMreports =? then I don't know, I think you'll have to wait for Detekt plugin fixgammax
10/15/2021, 9:16 AM-SNAPSHOT version where this got fixed?Michael Marshall
10/15/2021, 9:20 AMMichael Marshall
10/15/2021, 10:30 AM// Hack to rename both main and test detekt reports to something consistent, assumes we run detektMain and then detektTest in order
tasks.withType<io.gitlab.arturbosch.detekt.Detekt> {
val mainReportFile = project.buildDir.resolve("reports/detekt/detektMain.xml")
doFirst {
// We run detektTest after detektMain, so the main report file will already exist
val newReportName = if (mainReportFile.exists()) "detektTest" else "detektMain"
reports {
xml.destination = file("${project.buildDir}/reports/detekt/$newReportName.xml")
html.destination = file("${project.buildDir}/reports/detekt/$newReportName.html")
txt.enabled = false
sarif.enabled = false
}
}
}ephemient
10/15/2021, 11:42 AMephemient
10/15/2021, 11:44 AMephemient
10/15/2021, 11:44 AMephemient
10/15/2021, 11:47 AMMichael Marshall
10/18/2021, 11:59 PMgammax
10/19/2021, 12:01 AMdoFirst to a task, that task’s cache will be considered invalid whenever you edit the build.gradlegammax
10/19/2021, 12:02 AMdoLastMichael Marshall
10/19/2021, 12:12 AMbuild folder, I’m okay with itgammax
10/19/2021, 12:13 AMgammax
10/19/2021, 12:13 AMgammax
10/19/2021, 12:14 AMcheck taskMichael Marshall
10/19/2021, 12:18 AMdetekt , not detektMain, is hooked up to check and that runs pretty quick. Our build.gradle isn’t edited very often either 🤷