Skip to content

Commit

Permalink
Enable gradle worker api by default
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Mar 8, 2024
1 parent 9380c74 commit d7aead3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Expand Up @@ -45,7 +45,13 @@ class DetektReportMergeSpec {
)
}

val gradleRunner = DslGradleRunner(projectLayout, builder.gradleBuildName, buildFileContent)
val gradleRunner = DslGradleRunner(
projectLayout,
builder.gradleBuildName,
buildFileContent,
// because of https://github.com/gradle/gradle/issues/28034
gradleProperties = mapOf("detekt.use.worker.api" to "false"),
)
gradleRunner.setupProject()
gradleRunner.runTasksAndExpectFailure("detekt", "sarifReportMerge", "--continue") { result ->
assertThat(result.output).contains("FAILURE: Build completed with 2 failures.")
Expand Down Expand Up @@ -108,7 +114,13 @@ class DetektReportMergeSpec {
)
}

val gradleRunner = DslGradleRunner(projectLayout, builder.gradleBuildName, buildFileContent)
val gradleRunner = DslGradleRunner(
projectLayout,
builder.gradleBuildName,
buildFileContent,
// because of https://github.com/gradle/gradle/issues/28034
gradleProperties = mapOf("detekt.use.worker.api" to "false"),
)
gradleRunner.setupProject()
gradleRunner.runTasksAndExpectFailure("detekt", "xmlReportMerge", "--continue") { result ->
assertThat(result.output).contains("FAILURE: Build completed with 2 failures.")
Expand Down
Expand Up @@ -151,7 +151,8 @@ class DetektPlugin : Plugin<Project> {
internal const val CONFIGURATION_DETEKT = "detekt"

internal fun ProviderFactory.isWorkerApiEnabled(): Boolean {
return gradleProperty("detekt.use.worker.api").getOrElse("false") == "true"
val defaultValue = isGradleVersionAtLeast(major = 7, minor = 6).toString()
return gradleProperty("detekt.use.worker.api").getOrElse(defaultValue).toBoolean()
}

@Incubating
Expand Down
2 changes: 1 addition & 1 deletion website/docs/gettingstarted/gradle.mdx
Expand Up @@ -310,7 +310,7 @@ detekt {
### <a name="gradle-properties">Options for detekt Gradle properties</a>

```groovy
// If set to true, enables Gradle Worker API for Detekt tasks. `false` by default.
// If set to true, enables Gradle Worker API for Detekt tasks. `true` by default.
// See the doc for the Worker API at https://docs.gradle.org/8.1/userguide/worker_api.html
detekt.use.worker.api = false
```
Expand Down
7 changes: 7 additions & 0 deletions website/docs/introduction/reporting.md
Expand Up @@ -74,6 +74,13 @@ tasks will not run if detekt finds issues.

:::

:::caution Attention

Because of [gradle/gradle#28034](https://github.com/gradle/gradle/issues/28034) to make `reportMerge` to work you need
to [disable the Worker API](https://detekt.dev/docs/gettingstarted/gradle#options-for-detekt-gradle-properties).

:::

The machine-readable report formats support report merging.
Detekt Gradle Plugin is not opinionated in how merging is set up and respects each project's build logic, especially
the merging makes most sense in a multi-module project. In this spirit, only Gradle tasks are provided.
Expand Down

0 comments on commit d7aead3

Please sign in to comment.