Skip to content

Commit

Permalink
Toolchains docs (#5293)
Browse files Browse the repository at this point in the history
* Add Groovy DSL test for jdkHome

* Add jdkHome to Gradle docs
  • Loading branch information
3flex committed Sep 11, 2022
1 parent a9f51ca commit 84276f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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

0 comments on commit 84276f2

Please sign in to comment.