|
| 1 | +import com.diffplug.gradle.spotless.SpotlessExtension |
| 2 | + |
1 | 3 | plugins { |
2 | 4 | id("com.diffplug.spotless") |
3 | 5 | } |
4 | 6 |
|
5 | 7 | spotless { |
6 | 8 | java { |
7 | 9 | googleJavaFormat() |
8 | | - licenseHeaderFile(rootProject.file("buildscripts/spotless.license.java"), "(package|import|public|// Includes work from:)") |
| 10 | + licenseHeaderFile( |
| 11 | + rootProject.file("buildscripts/spotless.license.java"), |
| 12 | + "(package|import|public|// Includes work from:)" |
| 13 | + ) |
| 14 | + toggleOffOn() |
9 | 15 | target("src/**/*.java") |
10 | 16 | } |
| 17 | + plugins.withId("groovy") { |
| 18 | + groovy { |
| 19 | + licenseHeaderFile( |
| 20 | + rootProject.file("buildscripts/spotless.license.java"), |
| 21 | + "(package|import|(?:abstract )?class)" |
| 22 | + ) |
| 23 | + endWithNewline() |
| 24 | + } |
| 25 | + } |
| 26 | + plugins.withId("scala") { |
| 27 | + scala { |
| 28 | + scalafmt() |
| 29 | + licenseHeaderFile( |
| 30 | + rootProject.file("buildscripts/spotless.license.java"), |
| 31 | + "(package|import|public)" |
| 32 | + ) |
| 33 | + target("src/**/*.scala") |
| 34 | + } |
| 35 | + } |
| 36 | + plugins.withId("org.jetbrains.kotlin.jvm") { |
| 37 | + kotlin { |
| 38 | + // not sure why it's not using the indent settings from .editorconfig |
| 39 | + ktlint().editorConfigOverride( |
| 40 | + mapOf( |
| 41 | + "indent_size" to "2", |
| 42 | + "continuation_indent_size" to "2", |
| 43 | + "max_line_length" to "160", |
| 44 | + "ktlint_standard_no-wildcard-imports" to "disabled", |
| 45 | + "ktlint_standard_package-name" to "disabled", |
| 46 | + // ktlint does not break up long lines, it just fails on them |
| 47 | + "ktlint_standard_max-line-length" to "disabled", |
| 48 | + // ktlint makes it *very* hard to locate where this actually happened |
| 49 | + "ktlint_standard_trailing-comma-on-call-site" to "disabled", |
| 50 | + // depends on ktlint_standard_wrapping |
| 51 | + "ktlint_standard_trailing-comma-on-declaration-site" to "disabled", |
| 52 | + // also very hard to find out where this happens |
| 53 | + "ktlint_standard_wrapping" to "disabled" |
| 54 | + ) |
| 55 | + ) |
| 56 | + licenseHeaderFile( |
| 57 | + rootProject.file("buildscripts/spotless.license.java"), |
| 58 | + "(package|import|class|// Includes work from:)" |
| 59 | + ) |
| 60 | + } |
| 61 | + } |
11 | 62 | kotlinGradle { |
12 | | - ktlint().editorConfigOverride(mapOf( |
13 | | - "indent_size" to "2", |
14 | | - "continuation_indent_size" to "2", |
15 | | - "max_line_length" to "160", |
16 | | - "ktlint_standard_no-wildcard-imports" to "disabled", |
17 | | - // ktlint does not break up long lines, it just fails on them |
18 | | - "ktlint_standard_max-line-length" to "disabled", |
19 | | - // ktlint makes it *very* hard to locate where this actually happened |
20 | | - "ktlint_standard_trailing-comma-on-call-site" to "disabled", |
21 | | - // depends on ktlint_standard_wrapping |
22 | | - "ktlint_standard_trailing-comma-on-declaration-site" to "disabled", |
23 | | - // also very hard to find out where this happens |
24 | | - "ktlint_standard_wrapping" to "disabled" |
25 | | - )) |
| 63 | + // not sure why it's not using the indent settings from .editorconfig |
| 64 | + ktlint().editorConfigOverride( |
| 65 | + mapOf( |
| 66 | + "indent_size" to "2", |
| 67 | + "continuation_indent_size" to "2", |
| 68 | + "max_line_length" to "160", |
| 69 | + "ktlint_standard_no-wildcard-imports" to "disabled", |
| 70 | + // ktlint does not break up long lines, it just fails on them |
| 71 | + "ktlint_standard_max-line-length" to "disabled", |
| 72 | + // ktlint makes it *very* hard to locate where this actually happened |
| 73 | + "ktlint_standard_trailing-comma-on-call-site" to "disabled", |
| 74 | + // depends on ktlint_standard_wrapping |
| 75 | + "ktlint_standard_trailing-comma-on-declaration-site" to "disabled", |
| 76 | + // also very hard to find out where this happens |
| 77 | + "ktlint_standard_wrapping" to "disabled", |
| 78 | + // we use variable names like v1_10Deps |
| 79 | + "ktlint_standard_property-naming" to "disabled", |
| 80 | + // prevent moving comment to next line in latestDepTestLibrary("xxx") { // see xxx module |
| 81 | + "ktlint_standard_function-literal" to "disabled" |
| 82 | + ) |
| 83 | + ) |
26 | 84 | } |
27 | | - format("misc") { |
28 | | - // not using "**/..." to help keep spotless fast |
29 | | - target( |
30 | | - ".gitattributes", |
31 | | - ".gitconfig", |
32 | | - ".editorconfig", |
33 | | - "*.md", |
34 | | - "src/**/*.md", |
35 | | - "docs/**/*.md", |
36 | | - "*.sh", |
37 | | - "src/**/*.properties") |
38 | | - leadingTabsToSpaces() |
39 | | - trimTrailingWhitespace() |
40 | | - endWithNewline() |
| 85 | +} |
| 86 | + |
| 87 | +// Use root declared tool deps to avoid issues with high concurrency. |
| 88 | +// see https://github.com/diffplug/spotless/tree/main/plugin-gradle#dependency-resolution-modes |
| 89 | +if (project == rootProject) { |
| 90 | + spotless { |
| 91 | + format("misc") { |
| 92 | + target( |
| 93 | + ".gitignore", |
| 94 | + ".gitattributes", |
| 95 | + ".gitconfig", |
| 96 | + ".editorconfig", |
| 97 | + "**/*.md", |
| 98 | + "**/*.sh", |
| 99 | + "**/*.dockerfile", |
| 100 | + "**/gradle.properties" |
| 101 | + ) |
| 102 | + leadingTabsToSpaces() |
| 103 | + trimTrailingWhitespace() |
| 104 | + endWithNewline() |
| 105 | + } |
| 106 | + predeclareDeps() |
| 107 | + } |
| 108 | + |
| 109 | + with(extensions["spotlessPredeclare"] as SpotlessExtension) { |
| 110 | + java { |
| 111 | + googleJavaFormat() |
| 112 | + } |
| 113 | + scala { |
| 114 | + scalafmt() |
| 115 | + } |
| 116 | + kotlin { |
| 117 | + ktlint() |
| 118 | + } |
| 119 | + kotlinGradle { |
| 120 | + ktlint() |
| 121 | + } |
41 | 122 | } |
42 | 123 | } |
0 commit comments