Skip to content

Commit 374070f

Browse files
committed
Migrate to convention plugins
1 parent 4e31af4 commit 374070f

27 files changed

+618
-557
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
uses: gradle/actions/setup-gradle@v5
3232
- name: Spotless ✨
3333
run: ./gradlew spotlessCheck
34-
- name: assemble testClasses
35-
run: ./gradlew assemble testClasses
34+
- name: assemble testClasses publishToMavenLocal
35+
run: ./gradlew assemble testClasses publishToMavenLocal
3636
build:
3737
needs: sanity-check
3838
strategy:

build-logic/build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
dependencies {
6+
implementation(libs.spotless.changelog.lib)
7+
implementation(libs.errorprone.gradle.lib)
8+
implementation(libs.errorprone.plugin)
9+
implementation(libs.nexus.publish.lib)
10+
implementation(libs.spotbugs.gradle.lib)
11+
implementation(libs.rewrite.gradle.lib)
12+
implementation(libs.test.logger.gradle.lib)
13+
implementation(libs.groovy.xml)
14+
implementation(libs.develocity.gradle.lib)
15+
implementation(libs.spotless.gradle.lib)
16+
17+
// TODO: https://github.com/gradle/gradle/issues/15383
18+
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
19+
}

build-logic/settings.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dependencyResolutionManagement {
2+
repositories {
3+
mavenCentral()
4+
gradlePluginPortal()
5+
}
6+
versionCatalogs {
7+
create("libs") {
8+
from(files("../gradle/libs.versions.toml"))
9+
}
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import org.gradle.accessors.dm.LibrariesForLibs
2+
import org.gradle.api.Project
3+
import org.gradle.kotlin.dsl.getByType
4+
5+
internal val Project.libs: LibrariesForLibs get() = extensions.getByType()
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
plugins {
2+
id("com.diffplug.spotless-changelog")
3+
}
4+
5+
val kind = when (project.name) {
6+
"plugin-gradle" -> "gradle"
7+
"plugin-maven" -> "maven"
8+
else -> {
9+
check(project == rootProject)
10+
"lib"
11+
}
12+
}
13+
14+
val releaseTitle = when (project.name) {
15+
"plugin-gradle" -> "Gradle Plugin"
16+
"plugin-maven" -> "Maven Plugin"
17+
else -> "Lib"
18+
}
19+
20+
spotlessChangelog {
21+
changelogFile(file("CHANGES.md"))
22+
// appendDashSnapshotUnless_dashPrelease(true)
23+
branch("release")
24+
tagPrefix("${kind}/")
25+
commitMessage("Published ${kind}/{{version}}")
26+
tagMessage("{{changes}}")
27+
runAfterPush("gh release create ${kind}/{{version}} --title '${releaseTitle} v{{version}}' --notes-from-tag")
28+
rootProject.extra["versionLast"] = versionLast
29+
rootProject.extra["versionNext"] = versionNext
30+
}
31+
32+
if (project == rootProject) {
33+
gradle.taskGraph.whenReady {
34+
val changelogPushTasks = allTasks.filter { it.name == "changelogPush" }.map { it.path }
35+
if (changelogPushTasks.size > 1) {
36+
error("Run changelogPush one at a time:\n" + changelogPushTasks.joinToString("\n"))
37+
} else if (changelogPushTasks.size == 1) {
38+
val isPlugin =
39+
changelogPushTasks[0] == ":plugin-gradle:changelogPush" || changelogPushTasks[0] == ":plugin-maven:changelogPush"
40+
if (isPlugin) {
41+
val extension = extensions.getByName("spotlessChangelog")
42+
val parsedChangelog = extension.javaClass.getMethod("getParsedChangelog").invoke(extension)
43+
val noUnreleasedChanges =
44+
parsedChangelog.javaClass.getMethod("noUnreleasedChanges").invoke(parsedChangelog) as Boolean
45+
46+
if (!noUnreleasedChanges) {
47+
if (rootProject.findProperty("ignoreUnreleasedLib") != "true") {
48+
val unreleased =
49+
parsedChangelog.javaClass.getMethod("unreleasedChanges").invoke(parsedChangelog)
50+
error(
51+
"You're going to publish ${changelogPushTasks[0]}, but there are unreleased features in lib!\n" +
52+
"You should run :changelogPush first! Else you'll be missing out on:\n" +
53+
"${unreleased}\n" +
54+
"If it's okay to miss those and link against the old ${rootProject.extra["versionLast"]} then " +
55+
"add -PignoreUnreleasedLib=true"
56+
)
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import net.ltgt.gradle.errorprone.CheckSeverity
2+
import net.ltgt.gradle.errorprone.ErrorProneOptions
3+
4+
plugins {
5+
id("net.ltgt.errorprone")
6+
}
7+
8+
tasks.withType<JavaCompile>().configureEach {
9+
(options as ExtensionAware).extensions.configure<ErrorProneOptions>("errorprone") {
10+
if (System.getenv("error-prone")?.toBoolean() == true) {
11+
enable()
12+
} else {
13+
disable()
14+
}
15+
disableAllWarnings = true
16+
check("AnnotateFormatMethod", CheckSeverity.OFF)
17+
check("FunctionalInterfaceMethodChanged", CheckSeverity.OFF)
18+
check("ImmutableEnumChecker", CheckSeverity.OFF)
19+
check("InlineMeSuggester", CheckSeverity.OFF)
20+
check("JavaxInjectOnAbstractMethod", CheckSeverity.OFF)
21+
check("OverridesJavaxInjectableMethod", CheckSeverity.OFF)
22+
check("ReturnValueIgnored", CheckSeverity.ERROR)
23+
check("SelfAssignment", CheckSeverity.ERROR)
24+
check("StringJoin", CheckSeverity.ERROR)
25+
check("UnnecessarilyFullyQualified", CheckSeverity.ERROR)
26+
check("UnnecessaryLambda", CheckSeverity.ERROR)
27+
excludedPaths = ".*/GradleIntegrationHarness.java"
28+
}
29+
}
30+
31+
dependencies {
32+
errorprone(libs.errorprone.core)
33+
}

0 commit comments

Comments
 (0)