|
| 1 | +import com.diffplug.gradle.spotless.FreshMarkExtension |
| 2 | + |
| 3 | +plugins { |
| 4 | + id("com.diffplug.spotless") |
| 5 | +} |
| 6 | + |
| 7 | +val freshMarkSetup: (FreshMarkExtension) -> Unit = { |
| 8 | + it.target("*.md") |
| 9 | + it.propertiesFile(rootProject.file("gradle.properties")) |
| 10 | + it.properties { |
| 11 | + put("yes", ":+1:") |
| 12 | + put("no", ":white_large_square:") |
| 13 | + } |
| 14 | + it.leadingTabsToSpaces(2) |
| 15 | + it.endWithNewline() |
| 16 | +} |
| 17 | + |
| 18 | +spotless { |
| 19 | + if (project == rootProject) { |
| 20 | + freshmark { |
| 21 | + freshMarkSetup(this) |
| 22 | + ratchetFrom(null) |
| 23 | + } |
| 24 | + } else { |
| 25 | + java { |
| 26 | + ratchetFrom("origin/main") |
| 27 | + bumpThisNumberIfACustomStepChanges(1) |
| 28 | + licenseHeaderFile(rootProject.file("gradle/spotless.license")) |
| 29 | + importOrderFile(rootProject.file("gradle/spotless.importorder")) |
| 30 | + eclipse().configFile(rootProject.file("gradle/spotless.eclipseformat.xml")) |
| 31 | + trimTrailingWhitespace() |
| 32 | + removeUnusedImports() |
| 33 | + formatAnnotations() |
| 34 | + forbidWildcardImports() |
| 35 | + forbidRegex( |
| 36 | + "ForbidGradleInternal", |
| 37 | + "import org\\.gradle\\.api\\.internal\\.(.*)", |
| 38 | + "Don't use Gradle's internal API" |
| 39 | + ) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + groovyGradle { |
| 44 | + target("*.gradle", "gradle/*.gradle") |
| 45 | + greclipse().configFile( |
| 46 | + rootProject.files( |
| 47 | + "gradle/spotless.eclipseformat.xml", |
| 48 | + "gradle/spotless.groovyformat.prefs" |
| 49 | + ) |
| 50 | + ) |
| 51 | + } |
| 52 | + |
| 53 | + format("dotfiles") { |
| 54 | + target(".gitignore", ".gitattributes", ".editorconfig") |
| 55 | + leadingTabsToSpaces(2) |
| 56 | + trimTrailingWhitespace() |
| 57 | + endWithNewline() |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +// Extra freshmark logic from spotless-freshmark.gradle |
| 62 | +if (project == rootProject) { |
| 63 | + val versionLast = rootProject.extra["versionLast"]?.toString() |
| 64 | + val versionNext = rootProject.extra["versionNext"]?.toString() |
| 65 | + |
| 66 | + if (versionLast != null && versionNext != null) { |
| 67 | + if (tasks.names.contains("changelogCheck")) { |
| 68 | + spotless { |
| 69 | + freshmark { |
| 70 | + properties { |
| 71 | + put("versionLast", versionLast) |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + // create a freshmark apply task manually |
| 77 | + val freshMarkApply = FreshMarkExtension(spotless) |
| 78 | + freshMarkSetup(freshMarkApply) |
| 79 | + freshMarkApply.properties { |
| 80 | + put("versionLast", versionNext) |
| 81 | + } |
| 82 | + |
| 83 | + val changelogBumpFreshMark = freshMarkApply.createIndependentApplyTask("changelogBumpFreshmark") |
| 84 | + changelogBumpFreshMark.dependsOn(tasks.named("changelogBump")) |
| 85 | + |
| 86 | + val changelogBumpFreshMarkGitAdd by tasks.registering(Exec::class) { |
| 87 | + dependsOn(changelogBumpFreshMark) |
| 88 | + commandLine("git", "add", "*.md") |
| 89 | + } |
| 90 | + |
| 91 | + tasks.named("changelogPush") { |
| 92 | + dependsOn(changelogBumpFreshMarkGitAdd) |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments