Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolchains docs #5293

Merged
merged 2 commits into from Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -51,6 +51,7 @@ class DetektTaskGroovyDslSpec {
| classpath.setFrom(files("config.yml"))
| languageVersion = "1.6"
| jvmTarget = "1.8"
| jdkHome = file("path/to/jdk")
| debug = true
| parallel = true
| disableDefaultRuleSets = true
Expand Down Expand Up @@ -96,6 +97,7 @@ class DetektTaskGroovyDslSpec {
| config.setFrom(files("config.yml"))
| classpath.setFrom(files("config.yml"))
| jvmTarget = "1.8"
| jdkHome = file("path/to/jdk")
| debug = true
| parallel = true
| disableDefaultRuleSets = true
Expand Down
19 changes: 16 additions & 3 deletions website/docs/gettingstarted/gradle.mdx
Expand Up @@ -328,19 +328,30 @@ tasks.named("detekt").configure {

### Using Type Resolution

Type resolution is experimental and works only for [predefined tasks listed above](#a-nametasksavailable-plugin-tasksa)
Type resolution is experimental and works only for [predefined tasks listed above](#available-plugin-tasks)
or when implementing a custom detekt task with the `classpath` and `jvmTarget` properties present.

`jdkHome` is also available as an input. When this is unset, analysis is performed using the JDK classes of the JDK that
Gradle is running with (shown by the `./gradlew --version` command). This can be an issue if the Gradle JDK and the
project JDK doesn't match e.g. if Gradle runs under Java 8 but the project uses classes only available in Java 9 or
higher. Setting `jdkHome` to the Java 9 JDK path will allow for more correct analysis.

`jdkHome` and `jvmTarget` are set automatically when applying a toolchain using either
[`java`](https://docs.gradle.org/current/userguide/toolchains.html) or
[`kotlin`](https://kotlinlang.org/docs/gradle.html#gradle-java-toolchains-support).

More information on type resolution are available on the [type resolution](type-resolution.md) page.

#### Groovy DSL

```groovy
tasks.withType(io.gitlab.arturbosch.detekt.Detekt).configureEach {
jvmTarget = "1.8"
jvmTarget = '1.8'
jdkHome.set(file('path/to/jdkHome'))
}
tasks.withType(io.gitlab.arturbosch.detekt.DetektCreateBaselineTask).configureEach {
jvmTarget = "1.8"
jvmTarget = '1.8'
jdkHome.set(file('path/to/jdkHome'))
}
```

Expand All @@ -349,9 +360,11 @@ tasks.withType(io.gitlab.arturbosch.detekt.DetektCreateBaselineTask).configureEa
```kotlin
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
this.jvmTarget = "1.8"
jdkHome.set(file("path/to/jdkHome"))
}
tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach {
this.jvmTarget = "1.8"
jdkHome.set(file("path/to/jdkHome"))
}
```

Expand Down