diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 0000000000..8a72da2ef2 --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + `kotlin-dsl` +} + +val versionCatalog = versionCatalogs.named("libs") + +fun plugin(alias: String): String { + val p = versionCatalog.findPlugin(alias).get().get() + return "${p.pluginId}:${p.pluginId}.gradle.plugin:${p.version}" +} + +dependencies { + implementation(plugin("spotless")) + implementation(plugin("spotless-changelog")) + implementation("com.diffplug.spotless-changelog:spotless-changelog-lib:3.1.2") + implementation(plugin("spotbugs")) + implementation(plugin("errorprone")) + implementation(plugin("rewrite")) + implementation(plugin("test-logger")) + implementation(plugin("nexus-publish")) + implementation(plugin("develocity")) + + // TODO: https://github.com/gradle/gradle/issues/15383 + implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 0000000000..a51240b49f --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,13 @@ +dependencyResolutionManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "build-logic" diff --git a/build-logic/src/main/kotlin/Ext.kt b/build-logic/src/main/kotlin/Ext.kt new file mode 100644 index 0000000000..6ab5ed4df6 --- /dev/null +++ b/build-logic/src/main/kotlin/Ext.kt @@ -0,0 +1,35 @@ +import com.diffplug.spotless.changelog.gradle.ChangelogExtension +import java.util.Base64 +import org.gradle.accessors.dm.LibrariesForLibs +import org.gradle.api.Project +import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.getByType + +internal val Project.libs: LibrariesForLibs + get() = extensions.findByType() ?: rootProject.extensions.getByType() + +val Project.spotlessChangelog: ChangelogExtension + get() = extensions.findByType() ?: rootProject.extensions.getByType() + +val Project.rootSpotlessChangelog: ChangelogExtension + get() = rootProject.extensions.getByType() + +fun Project.requiredProperty(name: String): String = + findProperty(name)?.toString() + ?: error("$path is missing the '$name' property, which is required") + +// getMimeDecoder, not getDecoder: the basic decoder rejects the newlines that `base64`/`openssl +// base64` leave in a wrapped secret, whereas Groovy's String.decodeBase64 (used before the Kotlin +// DSL migration) skipped whitespace. +fun decode64(varName: String): String { + val envValue = System.getenv(varName) ?: return "" + return String(Base64.getMimeDecoder().decode(envValue), Charsets.UTF_8) +} + +// Groovy's String.toBoolean() -- what this used before the Kotlin DSL migration -- accepts "true", +// "y" and "1", ignoring case. Kotlin's toBoolean() only accepts "true", so the short forms would +// silently become no-ops. +fun String.toBooleanGroovy(): Boolean = trim().lowercase() in setOf("true", "y", "1") + +val isCiServer: Boolean + get() = System.getenv().containsKey("CI") diff --git a/build-logic/src/main/kotlin/spotless.changelog.gradle.kts b/build-logic/src/main/kotlin/spotless.changelog.gradle.kts new file mode 100644 index 0000000000..5db9e0ba04 --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.changelog.gradle.kts @@ -0,0 +1,59 @@ +plugins { + id("com.diffplug.spotless-changelog") +} + +val (kind, releaseTitle) = + when (project.name) { + "plugin-gradle" -> "gradle" to "Gradle Plugin" + "plugin-maven" -> "maven" to "Maven Plugin" + else -> { + check(project == rootProject) + "lib" to "Lib" + } + } + +// the root project and plugins have their own changelogs +spotlessChangelog { + changelogFile("CHANGES.md") + // need -Prelease=true in order to do a publish + setAppendDashSnapshotUnless_dashPrelease(true) + branch("release") + tagPrefix("$kind/") + commitMessage("Published $kind/{{version}}") // {{version}} will be replaced + tagMessage("{{changes}}") + runAfterPush( + "gh release create $kind/{{version}} --title '$releaseTitle v{{version}}' --notes-from-tag" + ) +} + +if (project == rootProject) { + gradle.taskGraph.whenReady { + val changelogPushTasks = allTasks.filter { it.name == "changelogPush" }.map { it.path } + if (changelogPushTasks.size > 1) { + // make sure only one changelog gets published per tag/commit + throw IllegalArgumentException( + "Run changelogPush one at a time:\n" + changelogPushTasks.joinToString("\n") + ) + } + if (changelogPushTasks.size == 1) { + // if the one thing being published is a plugin, make sure there aren't any unreleased + // changes in lib + val isPlugin = + changelogPushTasks[0] == ":plugin-gradle:changelogPush" || + changelogPushTasks[0] == ":plugin-maven:changelogPush" + if ( + isPlugin && + !rootSpotlessChangelog.parsedChangelog.noUnreleasedChanges() && + rootProject.findProperty("ignoreUnreleasedLib")?.toString() != "true" + ) { + throw IllegalArgumentException( + "You're going to publish ${changelogPushTasks[0]}, but there are unreleased features in lib!\n" + + "You should run :changelogPush first! Else you'll be missing out on:\n" + + "${rootSpotlessChangelog.parsedChangelog.unreleasedChanges()}\n" + + "If it's okay to miss those and link against the old ${rootSpotlessChangelog.versionLast} then " + + "add -PignoreUnreleasedLib=true" + ) + } + } + } +} diff --git a/build-logic/src/main/kotlin/spotless.error-prone.gradle.kts b/build-logic/src/main/kotlin/spotless.error-prone.gradle.kts new file mode 100644 index 0000000000..45a97a7439 --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.error-prone.gradle.kts @@ -0,0 +1,38 @@ +import net.ltgt.gradle.errorprone.errorprone + +plugins { + id("net.ltgt.errorprone") +} + +tasks.withType().configureEach { + options.errorprone { + enabled = System.getenv("error-prone")?.toBooleanGroovy() == true + // https://github.com/diffplug/spotless/issues/2745 + // https://github.com/google/error-prone/issues/5365 + disableAllWarnings = true + disable( + "AnnotateFormatMethod", // We don't want to use ErrorProne's annotations. + "FunctionalInterfaceMethodChanged", + "ImmutableEnumChecker", // We don't want to use ErrorProne's annotations. + "InlineMeSuggester", // We don't want to use ErrorProne's annotations. + "JavaxInjectOnAbstractMethod", + "OverridesJavaxInjectableMethod", + "ReturnValueIgnored", // We don't want to use ErrorProne's annotations. + ) + error( + "ReturnValueIgnored", + "SelfAssignment", + "StringJoin", + "UnnecessarilyFullyQualified", + "UnnecessaryLambda", + ) + // bug: this only happens when the file is dirty. + // might be an up2date (caching) issue, as file is currently in corrupt state. + // ForbidGradleInternal(import + excludedPaths = ".*/GradleIntegrationHarness.java" + } +} + +dependencies { + errorprone(libs.errorprone.core) +} diff --git a/build-logic/src/main/kotlin/spotless.java-publish.gradle.kts b/build-logic/src/main/kotlin/spotless.java-publish.gradle.kts new file mode 100644 index 0000000000..3c33d1d817 --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.java-publish.gradle.kts @@ -0,0 +1,181 @@ +plugins { + `java-library` + `maven-publish` + signing +} + +java { + withJavadocJar() + withSourcesJar() +} + +tasks.named("sourcesJar") { + dependsOn(tasks.jar) +} + +tasks.withType().configureEach { + options { + (this as? StandardJavadocDocletOptions)?.apply { + encoding = Charsets.UTF_8.name() + // Where it's possible to name parameters and methods clearly enough that javadoc is not + // necessary, why make the code bigger? Thus, no javadoc warnings. + addStringOption("Xdoclint:none", "-quiet") + addStringOption("Xwerror", "-quiet") + addStringOption("source", "17") + val artifactId = requiredProperty("artifactId") + val org = requiredProperty("org") + val version = project.version.toString() + val group = project.group.toString() + val javadocInfo = + "

$group:$artifactId:$version by DiffPlug

" + header = javadocInfo + + val dotdotGradle = if (project.name.startsWith("eclipse-")) "../../gradle" else "../gradle" + linksOffline("https://docs.gradle.org/6.1.1/javadoc/", "$dotdotGradle/javadoc/gradle") + val versionLast = rootSpotlessChangelog.versionLast + linksOffline( + "https://javadoc.io/static/com.diffplug.spotless/spotless-lib/$versionLast", + "$dotdotGradle/javadoc/spotless-lib", + ) + linksOffline( + "https://javadoc.io/static/com.diffplug.spotless/spotless-lib-extra/$versionLast", + "$dotdotGradle/javadoc/spotless-lib-extra", + ) + } + } +} + +// make sure bad javadoc breaks the build +tasks.check { + dependsOn(tasks.javadoc) +} + +afterEvaluate { + val isExt = project.name.startsWith("eclipse-") + val artifactId = requiredProperty("artifactId") + val org = requiredProperty("org") + val isPluginMaven = artifactId == "spotless-maven-plugin" + val isPluginGradle = pluginManager.hasPlugin("java-gradle-plugin") + + publishing { + publications { + // java-gradle-plugin creates 'pluginMaven' from its own afterEvaluate, with the java + // component already attached. Ours has to run after that one, which it only does because + // java-gradle-plugin is applied earlier in the consumer's plugins block. If that ever + // inverts we would create an empty publication here and ship a POM with no jar, so check + // rather than silently degrade. + val existing = findByName("pluginMaven") as? MavenPublication + check(!isPluginGradle || existing != null) { + "${project.path} applies java-gradle-plugin, which must be applied before " + + "spotless.java-publish so that it can create the 'pluginMaven' publication" + } + val pluginMaven = + existing ?: create("pluginMaven") { from(components["java"]) } + + pluginMaven.apply { + groupId = project.group.toString() + this.artifactId = artifactId + version = project.version.toString() + + pom { + name = artifactId + description = project.description + url = "https://github.com/$org/${rootProject.name}" + scm { + url = "https://github.com/$org/${rootProject.name}" + connection = "scm:git:https://github.com/$org/${rootProject.name}.git" + developerConnection = "scm:git:ssh:git@github.com/$org/${rootProject.name}.git" + } + licenses { + license { + if (isExt) { + name = "Eclipse Public License - v 1.0" + url = "https://www.eclipse.org/legal/epl-v10.html" + } else { + name = "The Apache Software License, Version 2.0" + url = "https://www.apache.org/licenses/LICENSE-2.0.txt" + } + distribution = "repo" + } + } + developers { + if (isExt) { + @Suppress("UNCHECKED_CAST") + val devs = project.findProperty("developers") as? Map> + devs?.forEach { (extId, extValues) -> + developer { + id = extId + name = extValues["name"] + email = extValues["email"] + } + } + } else { + if (isPluginMaven) { + developer { + id = "lutovich" + name = "Konstantin Lutovich" + email = "konstantin.lutovich@neotechnology.com" + } + } + developer { + id = "nedtwigg" + name = "Ned Twigg" + email = "ned.twigg@diffplug.com" + } + } + } + if (isPluginMaven) { + // Maven plugin requires Maven 3.1.0+ to run + withXml { + val rootNode = asNode() + val prerequisites = rootNode.appendNode("prerequisites") + prerequisites.appendNode("maven", "3.1.0") + } + } + } + } + } + if (System.getenv("JITPACK") == "true" || project.version.toString().endsWith("-SNAPSHOT")) { + signing { + isRequired = false + } + } else { + signing { + val gpgKey = decode64("ORG_GRADLE_PROJECT_gpg_key64") + useInMemoryPgpKeys( + "0x4272C851", + gpgKey, + System.getenv("ORG_GRADLE_PROJECT_gpg_passphrase"), + ) + sign(publishing.publications) + } + + // find the project with the changelog (this project for plugins, root project for libs) + val changelogProject = if (tasks.names.contains("changelogBump")) project else rootProject + val changelogTasks = changelogProject.tasks + + // ensures that nothing will be built if changelogPush will end up failing + tasks.jar { + dependsOn(changelogTasks.named("changelogCheck")) + } + + // ensures that changelog bump and push only happens if the publish was successful + val thisProj = project + changelogTasks.named("changelogBump") { + dependsOn( + ":${thisProj.path.removePrefix(":")}:publishPluginMavenPublicationToSonatypeRepository" + ) + dependsOn(":closeAndReleaseSonatypeStagingRepository") + // if we have a Gradle plugin, we need to push it up to the plugin portal too + if (thisProj.tasks.names.contains("publishPlugins")) { + dependsOn(thisProj.tasks.named("publishPlugins")) + } + } + } + } +} + +tasks.withType().configureEach { + isPreserveFileTimestamps = false + isReproducibleFileOrder = true +} diff --git a/build-logic/src/main/kotlin/spotless.java-setup.gradle.kts b/build-logic/src/main/kotlin/spotless.java-setup.gradle.kts new file mode 100644 index 0000000000..e759c2720d --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.java-setup.gradle.kts @@ -0,0 +1,45 @@ +import com.github.spotbugs.snom.Confidence +import com.github.spotbugs.snom.SpotBugsTask + +plugins { + id("java") + id("com.github.spotbugs") + id("spotless.error-prone") + id("spotless.spotless-conventions") +} + +tasks.withType().configureEach { + options.encoding = Charsets.UTF_8.name() + options.release = libs.versions.jdk.release.map { it.toInt() } +} + +spotbugs { + ignoreFailures = false // bug free or it doesn't ship! + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = Confidence.MEDIUM + omitVisitors = + listOf( + // https://spotbugs.readthedocs.io/en/latest/detectors.html#constructorthrow + "ConstructorThrow", + // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref + "FindReturnRef", + ) +} + +tasks.spotbugsTest { + enabled = false +} + +tasks.withType().configureEach { + outputs.file(project.layout.buildDirectory.file("reports/spotbugs/${name}.html")) + outputs.file(project.layout.buildDirectory.file("spotbugs/auxclasspath/${name}")) + reports.create("html") { + required = true + } +} + +dependencies { + compileOnly(libs.jcip.annotations) + compileOnly(spotbugs.toolVersion.map { "com.github.spotbugs:spotbugs-annotations:$it" }) + compileOnly(libs.jsr305) +} diff --git a/build-logic/src/main/kotlin/spotless.nexus-publish.gradle.kts b/build-logic/src/main/kotlin/spotless.nexus-publish.gradle.kts new file mode 100644 index 0000000000..a1c54c8487 --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.nexus-publish.gradle.kts @@ -0,0 +1,24 @@ +plugins { + id("io.github.gradle-nexus.publish-plugin") +} + +group = "com.diffplug.spotless" + +nexusPublishing { + repositories { + sonatype { + nexusUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/") + snapshotRepositoryUrl = uri("https://central.sonatype.com/repository/maven-snapshots/") + username = System.getenv("ORG_GRADLE_PROJECT_nexus_user") + password = decode64("ORG_GRADLE_PROJECT_nexus_pass64") + } + } +} + +val initTask = tasks.named("initializeSonatypeStagingRepository") + +allprojects { + initTask.configure { + shouldRunAfter(tasks.withType()) + } +} diff --git a/build-logic/src/main/kotlin/spotless.rewrite.gradle.kts b/build-logic/src/main/kotlin/spotless.rewrite.gradle.kts new file mode 100644 index 0000000000..18f1718506 --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.rewrite.gradle.kts @@ -0,0 +1,25 @@ +plugins { + id("org.openrewrite.rewrite") +} + +rewrite { + activeRecipe("com.diffplug.spotless.openrewrite.SanityCheck") + exclusion( + listOf( + "**.dirty.java", + "**FormatterProperties.java", + "**_gradle_node_plugin_example_**", + "**idea/full.clean.java", + "**package-info.java", + "**testlib/src/main/resources**", + ) + ) + isExportDatatables = true + failOnDryRunResults = true +} + +dependencies { + rewrite(libs.rewrite.recipe.migrate.java) + rewrite(libs.rewrite.recipe.static.analysis) + rewrite(libs.rewrite.recipe.third.party) +} diff --git a/build-logic/src/main/kotlin/spotless.special-tests.gradle.kts b/build-logic/src/main/kotlin/spotless.special-tests.gradle.kts new file mode 100644 index 0000000000..8353e353d9 --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.special-tests.gradle.kts @@ -0,0 +1,41 @@ +import com.gradle.develocity.agent.gradle.test.DevelocityTestConfiguration + +plugins { + // this script configures the `test` task and registers Test tasks, so it needs java itself + // rather than relying on every consumer to declare it earlier in their plugins block + id("java") + id("com.adarshr.test-logger") +} + +// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations +val special = listOf("black", "buf", "clang", "gofmt", "idea", "npm", "shfmt") + +tasks.withType().configureEach { + if (isCiServer) { + configure { + testRetry { + maxRetries = 2 + maxFailures = 10 + } + } + } + // selfie https://selfie.dev/jvm/get-started#gradle + // optional, see "Overwrite everything" there + project.findProperty("selfie")?.let { environment("selfie", it) } + // optional, improves up-to-date checking + inputs.files(fileTree("src/test") { include("**/*.ss") }) + // https://docs.gradle.org/8.8/userguide/performance.html#execute_tests_in_parallel + maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1) +} + +tasks.named("test") { useJUnitPlatform { excludeTags(*special.toTypedArray()) } } + +special.forEach { tag -> + tasks.register("test${tag.replaceFirstChar { it.uppercase() }}") { + useJUnitPlatform { includeTags(tag) } + val testEnv = rootProject.file("testenv.properties") + if (testEnv.exists()) { + systemProperty("testenv.properties.path", testEnv.canonicalPath) + } + } +} diff --git a/build-logic/src/main/kotlin/spotless.spotless-conventions.gradle.kts b/build-logic/src/main/kotlin/spotless.spotless-conventions.gradle.kts new file mode 100644 index 0000000000..86f5fbe9ce --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.spotless-conventions.gradle.kts @@ -0,0 +1,48 @@ +plugins { + id("com.diffplug.spotless") +} + +spotless { + if (project != rootProject) { + java { + ratchetFrom("origin/main") + bumpThisNumberIfACustomStepChanges(1) + licenseHeaderFile(rootProject.file("gradle/spotless.license")) + importOrderFile(rootProject.file("gradle/spotless.importorder")) + eclipse().configFile(rootProject.file("gradle/spotless.eclipseformat.xml")) + trimTrailingWhitespace() + removeUnusedImports() + formatAnnotations() + forbidWildcardImports() + forbidRegex( + "ForbidGradleInternal", + """import org\.gradle\.api\.internal\.(.*)""", + "Don't use Gradle's internal API", + ) + } + } + kotlin { + target("build-logic/src/**/*.kt") + ktfmt(libs.ktfmt.get().version) + } + kotlinGradle { + target("*.gradle.kts", "build-logic/*.gradle.kts", "build-logic/src/**/*.gradle.kts") + ktfmt(libs.ktfmt.get().version) + } + groovyGradle { + target("*.gradle", "gradle/*.gradle") + greclipse() + .configFile( + rootProject.files( + "gradle/spotless.eclipseformat.xml", + "gradle/spotless.groovyformat.prefs", + ) + ) + } + format("dotfiles") { + target(".gitignore", ".gitattributes", ".editorconfig") + leadingTabsToSpaces(2) + trimTrailingWhitespace() + endWithNewline() + } +} diff --git a/build-logic/src/main/kotlin/spotless.spotless-freshmark.gradle.kts b/build-logic/src/main/kotlin/spotless.spotless-freshmark.gradle.kts new file mode 100644 index 0000000000..cd0206aebb --- /dev/null +++ b/build-logic/src/main/kotlin/spotless.spotless-freshmark.gradle.kts @@ -0,0 +1,63 @@ +import com.diffplug.gradle.spotless.FreshMarkExtension + +plugins { + id("com.diffplug.spotless") +} + +val freshmarkSetup: (FreshMarkExtension) -> Unit = { freshmark -> + freshmark.target("*.md") + freshmark.propertiesFile(rootProject.file("gradle.properties")) + freshmark.properties { + put("yes", ":+1:") + put("no", ":white_large_square:") + } + freshmark.leadingTabsToSpaces(2) + freshmark.endWithNewline() +} + +spotless { + freshmark { + freshmarkSetup(this) + // disable ratchetFrom for freshmark, because we always want to update the readme links + ratchetFrom(null as String?) + } +} + +// if this freshmark has a changelog file, then it has version-sensitive content +pluginManager.withPlugin("com.diffplug.spotless-changelog") { + val changelog = spotlessChangelog + val versionLast = changelog.versionLast + val versionNext = changelog.versionNext + + // normally we use versionLast for our freshmark + spotless { + freshmark { + properties { + put("versionLast", versionLast) + } + } + } + + // create a freshmark apply task manually + val freshmark = FreshMarkExtension(the()) + freshmarkSetup(freshmark) + freshmark.properties { + // that uses versionNext as versionLast + put("versionLast", versionNext) + } + + val changelogBumpFreshmark = freshmark.createIndependentApplyTask("changelogBumpFreshmark") + // freshmark should run after the changelog bump + changelogBumpFreshmark.dependsOn(tasks.named("changelogBump")) + + val changelogBumpFreshmarkGitAdd = + tasks.register("changelogBumpFreshmarkGitAdd") { + // this git add should run after the freshmark + dependsOn(changelogBumpFreshmark) + commandLine("git", "add", "*.md") + } + + tasks.named("changelogPush") { + dependsOn(changelogBumpFreshmarkGitAdd) + } +} diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 4d788a0a57..0000000000 --- a/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - alias(libs.plugins.equo.ide) - alias(libs.plugins.test.logger) apply false - alias(libs.plugins.spotless.changelog) apply false - alias(libs.plugins.plugin.publish) apply false - alias(libs.plugins.version.compatibility) apply false - alias(libs.plugins.nexus.publish) apply false - alias(libs.plugins.errorprone) apply false - alias(libs.plugins.rewrite) apply false - alias(libs.plugins.maven.plugin.development) apply false - alias(libs.plugins.p2deps) apply false -} - -equoIde { - branding().title('Spotless').icon(file('_images/spotless_logo.png')) - welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') - gradleBuildship().autoImport('.') -} - -apply from: rootProject.file('gradle/java-publish.gradle') -apply from: rootProject.file('gradle/changelog.gradle') -apply from: rootProject.file('gradle/rewrite.gradle') -allprojects { - apply from: rootProject.file('gradle/error-prone.gradle') - apply from: rootProject.file('gradle/spotless.gradle') -} -apply from: rootProject.file('gradle/spotless-freshmark.gradle') diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..58c59d06ec --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + alias(libs.plugins.equo.ide) + alias(libs.plugins.plugin.publish) apply false + alias(libs.plugins.version.compatibility) apply false + alias(libs.plugins.maven.plugin.development) apply false + alias(libs.plugins.p2deps) apply false + id("spotless.nexus-publish") + id("spotless.changelog") + id("spotless.rewrite") + id("spotless.spotless-freshmark") + id("spotless.spotless-conventions") +} + +equoIde { + branding().title("Spotless").icon(file("_images/spotless_logo.png")) + welcome().openUrl("https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md") + gradleBuildship().autoImport(".") +} diff --git a/gradle.properties b/gradle.properties index 82199090c0..314a778e40 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.parallel=true org.gradle.caching=true org.gradle.configuration-cache=true org.gradle.configuration-cache.parallel=true -org.gradle.tooling.parallel=true +org.gradle.kotlin.dsl.allWarningsAsErrors=true name=spotless description=Spotless - keep your code spotless with Gradle diff --git a/gradle/changelog.gradle b/gradle/changelog.gradle deleted file mode 100644 index 0fc643a634..0000000000 --- a/gradle/changelog.gradle +++ /dev/null @@ -1,56 +0,0 @@ -String kind -String releaseTitle -if (project.name == 'plugin-gradle') { - kind = 'gradle' - releaseTitle = 'Gradle Plugin' -} else if (project.name == 'plugin-maven') { - kind = 'maven' - releaseTitle = 'Maven Plugin' -} else { - assert project == rootProject - kind = 'lib' - releaseTitle = 'Lib' -} - -// the root project and plugins have their own changelogs -apply plugin: 'com.diffplug.spotless-changelog' -spotlessChangelog { - changelogFile 'CHANGES.md' - // need -Prelease=true in order to do a publish - appendDashSnapshotUnless_dashPrelease =true - - branch 'release' - tagPrefix "${kind}/" - commitMessage "Published ${kind}/{{version}}" // {{version}} will be replaced - tagMessage "{{changes}}" - runAfterPush "gh release create ${kind}/{{version}} --title '${releaseTitle} v{{version}}' --notes-from-tag" -} - -if (project == rootProject) { - gradle.taskGraph.whenReady { taskGraph -> - def changelogPushTasks = taskGraph.allTasks.stream() - .filter { t -> t.name == 'changelogPush' } - .map { t -> t.path } - .toList() - if (changelogPushTasks.size() > 1) { - // make sure only one changelog gets published per tag/commit - throw new IllegalArgumentException("Run changelogPush one at a time:\n" + changelogPushTasks.join('\n')) - } else if (changelogPushTasks.size() == 1) { - boolean isPlugin = (changelogPushTasks[0] == ':plugin-gradle:changelogPush') || (changelogPushTasks[1] == ':plugin-maven:changelogPush') - // if the one thing being published is a plugin - if (isPlugin) { - // make sure there aren't any unreleased changes in lib - if (!rootProject.spotlessChangelog.parsedChangelog.noUnreleasedChanges()) { - if (!("true".equals(rootProject.findProperty('ignoreUnreleasedLib')))) { - throw new IllegalArgumentException( - "You're going to publish ${changelogPushTasks[0]}, but there are unreleased features in lib!\n" + - "You should run :changelogPush first! Else you'll be missing out on:\n" + - "${rootProject.spotlessChangelog.parsedChangelog.unreleasedChanges()}\n" + - "If it's okay to miss those and link against the old ${rootProject.spotlessChangelog.versionLast} then " + - "add -PignoreUnreleasedLib=true") - } - } - } - } - } -} diff --git a/gradle/error-prone.gradle b/gradle/error-prone.gradle deleted file mode 100644 index 11cfd2015b..0000000000 --- a/gradle/error-prone.gradle +++ /dev/null @@ -1,34 +0,0 @@ -import static java.lang.System.getenv - -apply plugin: 'net.ltgt.errorprone' - -tasks.withType(JavaCompile).configureEach { - options.errorprone { - getenv('error-prone')?.toBoolean() ? enable() : disable() - disableAllWarnings = true // https://github.com/diffplug/spotless/issues/2745 https://github.com/google/error-prone/issues/5365 - disable( - 'AnnotateFormatMethod', // We don`t want to use ErrorProne's annotations. - 'FunctionalInterfaceMethodChanged', - 'ImmutableEnumChecker', // We don`t want to use ErrorProne's annotations. - 'InlineMeSuggester', // We don`t want to use ErrorProne's annotations. - 'JavaxInjectOnAbstractMethod', - 'OverridesJavaxInjectableMethod', - 'ReturnValueIgnored', // We don`t want to use ErrorProne's annotations. - ) - error( - 'ReturnValueIgnored', - 'SelfAssignment', - 'StringJoin', - 'UnnecessarilyFullyQualified', - 'UnnecessaryLambda', - ) - // bug: this only happens when the file is dirty. - // might be an up2date (caching) issue, as file is currently in corrupt state. - // ForbidGradleInternal(import - excludedPaths.set('.*/GradleIntegrationHarness.java') - } -} - -dependencies { - errorprone libs.errorprone.core -} diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle deleted file mode 100644 index e6c36dc566..0000000000 --- a/gradle/java-publish.gradle +++ /dev/null @@ -1,210 +0,0 @@ -import java.nio.charset.StandardCharsets - -def decode64(String varName) { - String envValue = System.env[varName] - if (envValue == null) { - return "" - } else { - return new String(envValue.decodeBase64(), "UTF-8") - } -} - -if (project.parent == null) { - group = 'com.diffplug.spotless' - def pass = System.env['ORG_GRADLE_PROJECT_nexus_pass64'] - if (pass != null) { - pass = pass.decodeBase64() - } - // it's the root project - apply plugin: 'io.github.gradle-nexus.publish-plugin' - nexusPublishing { - repositories { - sonatype { - nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/")) - snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/")) - username = System.env['ORG_GRADLE_PROJECT_nexus_user'] - password = decode64('ORG_GRADLE_PROJECT_nexus_pass64') - } - } - } - def initTask = tasks.named('initializeSonatypeStagingRepository') - allprojects { - initTask.configure { - shouldRunAfter(tasks.withType(Sign)) - } - } - return -} - -/////////// -// MAVEN // -/////////// -java { - withJavadocJar() - withSourcesJar() -} - -tasks.named('sourcesJar') { - dependsOn 'jar' -} - -apply plugin: 'maven-publish' -apply plugin: 'signing' - -// Where it's possible to name parameters and methods clearly enough -// that javadoc is not necessary, why make the code bigger? -// -// Thus, no javadoc warnings. -javadoc { - options.addStringOption('Xdoclint:none', '-quiet') - options.addStringOption('Xwerror', '-quiet') -} -// make sure bad javadoc breaks the build -tasks.named('check') { - dependsOn tasks.named('javadoc') -} - -// use markdown in javadoc -def makeLink = { url, text -> - "${text}" -} -def javadocInfo = '

' + makeLink("https://github.com/${org}/${name}", "${group}:${project.ext.artifactId}:${version}") + - ' by ' + makeLink('https://www.diffplug.com', 'DiffPlug') + '

' - -String dotdotGradle = project.name.startsWith('eclipse-') ? '../../gradle' : '../gradle' -javadoc { - options.encoding = 'UTF-8' - // Where it's possible to name parameters and methods clearly enough - // that javadoc is not necessary, why make the code bigger? - // - // Thus, no javadoc warnings. - options.addStringOption('Xdoclint:none', '-quiet') - options.addStringOption('source', '17') - // setup the header - options.header javadocInfo - // setup links - options.linksOffline('https://docs.gradle.org/6.1.1/javadoc/', "${dotdotGradle}/javadoc/gradle") - - // links to javadoc from the other versions - options.linksOffline("https://javadoc.io/static/com.diffplug.spotless/spotless-lib/${rootProject.spotlessChangelog.versionLast}", "${dotdotGradle}/javadoc/spotless-lib") - options.linksOffline("https://javadoc.io/static/com.diffplug.spotless/spotless-lib-extra/${rootProject.spotlessChangelog.versionLast}", "${dotdotGradle}/javadoc/spotless-lib-extra") -} - -//////////////// -// PUBLISHING // -//////////////// -final MAVEN_PLUGIN_ARTIFACT_NAME = 'spotless-maven-plugin' -boolean isExt = project.name.startsWith('eclipse-') -boolean isPluginMaven = project.ext.artifactId == 'spotless-maven-plugin' - -publishing { - publications { - pluginMaven(MavenPublication) { - if (project.ext.artifactId != 'spotless-plugin-gradle') { - from components.java - } - - groupId = project.group - artifactId = project.ext.artifactId - version = project.version - - def projectExtArtifactId = project.ext.artifactId - def projectDescription = project.description - def projectOrg = project.org - def rootProjectName = rootProject.name - - pom.withXml { - // add MavenCentral requirements to the POM - asNode().children().last() + { - resolveStrategy = Closure.DELEGATE_FIRST - name projectExtArtifactId - description projectDescription - url "https://github.com/${projectOrg}/${rootProjectName}" - scm { - url "https://github.com/${projectOrg}/${rootProjectName}" - connection "scm:git:https://github.com/${projectOrg}/${rootProjectName}.git" - developerConnection "scm:git:ssh:git@github.com/${projectOrg}/${rootProjectName}.git" - } - licenses { - if (isExt) { - license { - name 'Eclipse Public License - v 1.0' - url 'https://www.eclipse.org/legal/epl-v10.html' - distribution 'repo' - } - } else { - license { - name 'The Apache Software License, Version 2.0' - url 'https://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - } - if (isPluginMaven) { - // Maven plugin required Maven 3.1.0+ to run - prerequisites { maven '3.1.0' } - } - developers { - if (isExt) { - project.ext.developers.each { extId, extValues -> - developer { - id extId - name extValues['name'] - email extValues['email'] - } - } - } else { - if (isPluginMaven) { - developer { - id 'lutovich' - name 'Konstantin Lutovich' - email 'konstantin.lutovich@neotechnology.com' - } - } - developer { - id 'nedtwigg' - name 'Ned Twigg' - email 'ned.twigg@diffplug.com' - } - } - } - } - } - } - } -} - -if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) { - signing { - setRequired(false) - } -} else { - signing { - String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64') - useInMemoryPgpKeys('0x4272C851', gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase']) - sign(publishing.publications) - } - - // find the project with the changelog (this project for plugins, root project for libs) - def changelogTasks = (tasks.names.contains('changelogBump') ? project : rootProject).tasks - - // ensures that nothing will be built if changelogPush will end up failing - tasks.named('jar').configure { - dependsOn changelogTasks.named('changelogCheck') - } - // ensures that changelog bump and push only happens if the publish was successful - def thisProj = project - changelogTasks.named('changelogBump').configure { - dependsOn ":${thisProj.path}:publishPluginMavenPublicationToSonatypeRepository" - dependsOn ":closeAndReleaseSonatypeStagingRepository" - // if we have a Gradle plugin, we need to push it up to the plugin portal too - if (thisProj.tasks.names.contains('publishPlugins')) { - dependsOn thisProj.tasks.named('publishPlugins') - } - } -} - -tasks.withType(AbstractArchiveTask).configureEach { - preserveFileTimestamps = false - reproducibleFileOrder = true -} diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle deleted file mode 100644 index 4f624d3fb5..0000000000 --- a/gradle/java-setup.gradle +++ /dev/null @@ -1,43 +0,0 @@ -////////// -// JAVA // -////////// - -// setup java -apply plugin: 'java' -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' - options.release = libs.versions.jdk.release.get().toInteger() -} - -////////////// -// SPOTBUGS // -////////////// -apply plugin: 'com.github.spotbugs' -spotbugs { - ignoreFailures = false // bug free or it doesn't ship! - // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). - reportLevel = com.github.spotbugs.snom.Confidence.valueOf('MEDIUM') - omitVisitors = [ - // https://spotbugs.readthedocs.io/en/latest/detectors.html#constructorthrow - 'ConstructorThrow', - // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref - 'FindReturnRef', - ] -} -tasks.named('spotbugsTest') { - enabled = false -} - -tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { - outputs.file(project.layout.buildDirectory.file("reports/spotbugs/${it.name}.html")) - outputs.file(project.layout.buildDirectory.file("spotbugs/auxclasspath/${it.name}")) - reports { - html.enabled = true - } -} - -dependencies { - compileOnly libs.jcip.annotations - compileOnly "com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}" - compileOnly libs.jsr305 -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 03a754fa9a..b2860cda20 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -78,3 +78,4 @@ nexus-publish = "io.github.gradle-nexus.publish-plugin:2.0.0" errorprone = "net.ltgt.errorprone:5.1.1" rewrite = "org.openrewrite.rewrite:7.39.0" maven-plugin-development = "org.gradlex.maven-plugin-development:1.0.3" +develocity = "com.gradle.develocity:4.5.0" diff --git a/gradle/rewrite.gradle b/gradle/rewrite.gradle deleted file mode 100644 index 7f548130e5..0000000000 --- a/gradle/rewrite.gradle +++ /dev/null @@ -1,27 +0,0 @@ -apply plugin: 'org.openrewrite.rewrite' -rewrite { - activeRecipe('com.diffplug.spotless.openrewrite.SanityCheck') - exclusions.addAll( - '**.dirty.java', - '**FormatterProperties.java', - '**_gradle_node_plugin_example_**', - '**gradle/changelog.gradle', - '**gradle/java-publish.gradle', - '**idea/full.clean.java', - '**java-setup.gradle', - '**lib-extra/build.gradle', - '**lib/build.gradle', - '**package-info.java', - '**plugin-maven/build.gradle', - '**settings.gradle', - '**special-tests.gradle', - '**testlib/src/main/resources**' - ) - exportDatatables = true - failOnDryRunResults = true -} -dependencies { - rewrite libs.rewrite.recipe.migrate.java - rewrite libs.rewrite.recipe.static.analysis - rewrite libs.rewrite.recipe.third.party -} diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle deleted file mode 100644 index 658f86dd4e..0000000000 --- a/gradle/special-tests.gradle +++ /dev/null @@ -1,47 +0,0 @@ -apply plugin: 'com.adarshr.test-logger' - -// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations -def special = [ - 'black', - 'buf', - 'clang', - 'gofmt', - 'idea', - 'npm', - 'shfmt' -] - -boolean isCiServer = System.getenv().containsKey("CI") -tasks.withType(Test).configureEach { - if (isCiServer) { - develocity { - testRetry { - maxRetries = 2 - maxFailures = 10 - } - } - } - // selfie https://selfie.dev/jvm/get-started#gradle - environment project.properties.subMap([ - "selfie" - ]) // optional, see "Overwrite everything" below - inputs.files(fileTree("src/test") { - // optional, improves up-to-date checking - include "**/*.ss" - }) - // https://docs.gradle.org/8.8/userguide/performance.html#execute_tests_in_parallel - maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 -} -tasks.named('test').configure { - useJUnitPlatform { - excludeTags special as String[] - } -} -special.forEach { tag -> - tasks.register("test${tag.capitalize()}", Test) { - useJUnitPlatform { includeTags tag } - if (rootProject.file('testenv.properties').exists()) { - systemProperty 'testenv.properties.path', rootProject.file('testenv.properties').canonicalPath - } - } -} diff --git a/gradle/spotless-freshmark.gradle b/gradle/spotless-freshmark.gradle deleted file mode 100644 index 9608cb2cbb..0000000000 --- a/gradle/spotless-freshmark.gradle +++ /dev/null @@ -1,59 +0,0 @@ - -apply plugin: 'com.diffplug.spotless' - -import com.diffplug.gradle.spotless.FreshMarkExtension - -Action freshmarkSetup = { - it.target '*.md' - it.propertiesFile(rootProject.file('gradle.properties')) - it.properties { - it.put('yes', ':+1:') - it.put('no', ':white_large_square:') - } - it.leadingTabsToSpaces(2) - it.endWithNewline() -} - -spotless { - freshmark { - freshmarkSetup.execute(it) - // disable ratchetFrom for freshmark, because we always want to update the readme links - ratchetFrom null - } -} - -def versionLast = spotlessChangelog.versionLast -def versionNext = spotlessChangelog.versionNext - -// if this freshmark has a changelog file, then it has version-sensitive content -if (tasks.names.contains('changelogCheck')) { - // normally we use versionLast for our freshmark - spotless { - freshmark { - properties { - it.put('versionLast', versionLast) - } - } - } - - // create a freshmark apply task manually - FreshMarkExtension freshmark = new FreshMarkExtension(spotless) - freshmarkSetup.execute(freshmark) - freshmark.properties { - // that uses versionNext as versionLast - it.put('versionLast', versionNext) - } - def changelogBumpFreshmark = freshmark.createIndependentApplyTask('changelogBumpFreshmark') - // freshmark should run after the changelog bump - changelogBumpFreshmark.dependsOn tasks.named('changelogBump') - - def changelogBumpFreshmarkGitAdd = tasks.register('changelogBumpFreshmarkGitAdd', Exec) { - // this git add should run after the freshmark - dependsOn(changelogBumpFreshmark) - // do the git add - commandLine 'git', 'add', '*.md' - } - tasks.named('changelogPush').configure { - dependsOn changelogBumpFreshmarkGitAdd - } -} diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle deleted file mode 100644 index 5862a633ea..0000000000 --- a/gradle/spotless.gradle +++ /dev/null @@ -1,28 +0,0 @@ -apply plugin: 'com.diffplug.spotless' -spotless { - if (project != rootProject) { - // the rootProject doesn't have any java - java { - ratchetFrom 'origin/main' - bumpThisNumberIfACustomStepChanges(1) - licenseHeaderFile rootProject.file('gradle/spotless.license') - importOrderFile rootProject.file('gradle/spotless.importorder') - eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml') - trimTrailingWhitespace() - removeUnusedImports() - formatAnnotations() - forbidWildcardImports() - forbidRegex('ForbidGradleInternal', 'import org\\.gradle\\.api\\.internal\\.(.*)', "Don't use Gradle's internal API") - } - } - groovyGradle { - target '*.gradle', 'gradle/*.gradle' - greclipse().configFile rootProject.files('gradle/spotless.eclipseformat.xml', 'gradle/spotless.groovyformat.prefs') - } - format 'dotfiles', { - target '.gitignore', '.gitattributes', '.editorconfig' - leadingTabsToSpaces(2) - trimTrailingWhitespace() - endWithNewline() - } -} diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle deleted file mode 100644 index 9545924358..0000000000 --- a/lib-extra/build.gradle +++ /dev/null @@ -1,125 +0,0 @@ -plugins { - id 'java-library' - id 'dev.equo.p2deps' -} -ext.artifactId = project.artifactIdLibExtra -version = rootProject.spotlessChangelog.versionNext -apply from: rootProject.file('gradle/java-setup.gradle') -apply from: rootProject.file('gradle/java-publish.gradle') - -dependencies { - api projects.lib - // misc useful utilities - implementation libs.durian.core - implementation libs.durian.collect - // needed by GitAttributesLineEndings - implementation libs.jgit - implementation libs.concurrent.trees - // for eclipse - implementation libs.solstice - // the osgi dep is included in solstice, but it has some CVE's against it. - // 3.18.500 is the oldest, most-compatible version with no CVE's - // https://central.sonatype.com/artifact/org.eclipse.platform/org.eclipse.osgi/versions - implementation libs.osgi - - // testing - testImplementation projects.testlib - testImplementation libs.durian.io - testImplementation libs.jsr305 - testImplementation libs.junit.jupiter - testImplementation libs.assertj.core - testImplementation libs.durian.testlib - testRuntimeOnly "org.junit.platform:junit-platform-launcher" -} - -spotless { - java { - replaceRegex 'enforceSolsticeVersion', '"dev.equo.ide:solstice:(.*)"', "\"${libs.solstice.get().toString()}\"" - } -} - -apply from: rootProject.file('gradle/special-tests.gradle') -tasks.withType(Test).configureEach { - // needed for EclipseCdtFormatterStepTest - jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' -} - -def NEEDS_P2_DEPS = [ - // (alphabetic order please) - 'cdt', - 'groovy', - 'jdt' -] -for (needsP2 in NEEDS_P2_DEPS) { - sourceSets.register(needsP2) { - compileClasspath += sourceSets.main.output - runtimeClasspath += sourceSets.main.output - java {} - } - dependencies { - add("${needsP2}CompileOnly", libs.solstice) - } -} - -def jar = tasks.named('jar', Jar) { - for (needsP2 in NEEDS_P2_DEPS) { - from sourceSets.named(needsP2).map { it.output.classesDirs } - } -} - -tasks.withType(Test).configureEach { - dependsOn jar - classpath += jar.get().outputs.files - // P2 tests use a process-level file lock; parallel forks race for it. - // In-JVM synchronization in TestP2Provisioner is enough, so one fork is sufficient. - maxParallelForks = 1 -} - -apply plugin: 'dev.equo.p2deps' -p2deps { - into 'cdtCompileOnly', { - p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - p2repo 'https://download.eclipse.org/tools/cdt/releases/11.0/' - install 'org.eclipse.cdt.core' - } - into 'groovyCompileOnly', { - p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.26/' - install 'org.codehaus.groovy.eclipse.refactoring' - install 'org.codehaus.groovy.eclipse.core' - install 'org.eclipse.jdt.groovy.core' - install 'org.codehaus.groovy' - } - into 'jdtCompileOnly', { - p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - install 'org.eclipse.jdt.core' - } -} - -// Embedded Eclipse JDT lockfiles, see EclipseJdtLockfileMetadataTool. `verify` runs in CI so the -// lockfiles cannot silently drift from Eclipse's P2 metadata; `update` is run by hand whenever the -// default version moves. Both hit the Eclipse update sites, so neither is wired into `build`. -def eclipseJdtLockfileTool = { String entrypoint -> - return { - group = 'verification' - classpath = sourceSets.test.runtimeClasspath - mainClass = "com.diffplug.spotless.extra.java.EclipseJdtLockfileMetadataTool\$${entrypoint}" - workingDir = rootProject.projectDir - outputs.upToDateWhen { false } - } -} -tasks.register('verifyEclipseJdtLockfiles', JavaExec) { - configure eclipseJdtLockfileTool('Verify') - description = 'Checks the embedded Eclipse JDT lockfiles against Eclipse P2 metadata.' -} -tasks.register('updateEclipseJdtLockfiles', JavaExec) { - configure eclipseJdtLockfileTool('Update') - description = 'Regenerates the embedded Eclipse JDT lockfiles from Eclipse P2 metadata.' -} - -// we'll hold the core lib to a high standard -spotbugs { - // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). - reportLevel = com.github.spotbugs.snom.Confidence.valueOf('LOW') - excludeFilter = file("spotbugs-exclude.xml") -} diff --git a/lib-extra/build.gradle.kts b/lib-extra/build.gradle.kts new file mode 100644 index 0000000000..4118bcbb7b --- /dev/null +++ b/lib-extra/build.gradle.kts @@ -0,0 +1,133 @@ +import com.github.spotbugs.snom.Confidence + +plugins { + `java-library` + alias(libs.plugins.p2deps) + id("spotless.java-setup") + id("spotless.java-publish") + id("spotless.special-tests") +} + +extra["artifactId"] = property("artifactIdLibExtra") + +version = spotlessChangelog.versionNext + +dependencies { + api(projects.lib) + // misc useful utilities + implementation(libs.durian.core) + implementation(libs.durian.collect) + // needed by GitAttributesLineEndings + implementation(libs.jgit) + implementation(libs.concurrent.trees) + // for eclipse + implementation(libs.solstice) + // the osgi dep is included in solstice, but it has some CVE's against it. + // 3.18.500 is the oldest, most-compatible version with no CVE's + // https://central.sonatype.com/artifact/org.eclipse.platform/org.eclipse.osgi/versions + implementation(libs.osgi) + + // testing + testImplementation(projects.testlib) + testImplementation(libs.durian.io) + testImplementation(libs.jsr305) + testImplementation(libs.junit.jupiter) + testImplementation(libs.assertj.core) + testImplementation(libs.durian.testlib) + testRuntimeOnly("org.junit.platform:junit-platform-launcher") +} + +spotless { + java { + replaceRegex( + "enforceSolsticeVersion", + "\"dev.equo.ide:solstice:(.*)\"", + "\"${libs.solstice.get()}\"", + ) + } +} + +val needsP2Deps = + listOf( + // (alphabetic order please) + "cdt", + "groovy", + "jdt", + ) + +val mainSourceSet = sourceSets.named("main") + +for (needsP2 in needsP2Deps) { + sourceSets.register(needsP2) { + compileClasspath += mainSourceSet.get().output + runtimeClasspath += mainSourceSet.get().output + java {} + } + dependencies { add("${needsP2}CompileOnly", libs.solstice) } +} + +tasks.jar { + for (needsP2 in needsP2Deps) { + from(sourceSets.named(needsP2).map { it.output.classesDirs }) + } +} + +tasks.withType().configureEach { + // needed for EclipseCdtFormatterStepTest + jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") + dependsOn(tasks.jar) + classpath += tasks.jar.get().outputs.files + // P2 tests use a process-level file lock; parallel forks race for it. + // In-JVM synchronization in TestP2Provisioner is enough, so one fork is sufficient. + maxParallelForks = 1 +} + +p2deps { + into("cdtCompileOnly") { + p2repo("https://download.eclipse.org/eclipse/updates/4.26/") + p2repo("https://download.eclipse.org/tools/cdt/releases/11.0/") + install("org.eclipse.cdt.core") + } + into("groovyCompileOnly") { + p2repo("https://download.eclipse.org/eclipse/updates/4.26/") + p2repo( + "https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.26/" + ) + install("org.codehaus.groovy.eclipse.refactoring") + install("org.codehaus.groovy.eclipse.core") + install("org.eclipse.jdt.groovy.core") + install("org.codehaus.groovy") + } + into("jdtCompileOnly") { + p2repo("https://download.eclipse.org/eclipse/updates/4.26/") + install("org.eclipse.jdt.core") + } +} + +// Embedded Eclipse JDT lockfiles, see EclipseJdtLockfileMetadataTool. `verify` runs in CI so the +// lockfiles cannot silently drift from Eclipse's P2 metadata; `update` is run by hand whenever the +// default version moves. Both hit the Eclipse update sites, so neither is wired into `build`. +fun eclipseJdtLockfileTool(entrypoint: String): Action = Action { + group = "verification" + classpath = sourceSets.named("test").get().runtimeClasspath + mainClass = "com.diffplug.spotless.extra.java.EclipseJdtLockfileMetadataTool\$$entrypoint" + workingDir = rootProject.projectDir + outputs.upToDateWhen { false } +} + +tasks.register("verifyEclipseJdtLockfiles") { + eclipseJdtLockfileTool("Verify").execute(this) + description = "Checks the embedded Eclipse JDT lockfiles against Eclipse P2 metadata." +} + +tasks.register("updateEclipseJdtLockfiles") { + eclipseJdtLockfileTool("Update").execute(this) + description = "Regenerates the embedded Eclipse JDT lockfiles from Eclipse P2 metadata." +} + +// we'll hold the core lib to a high standard +spotbugs { + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = Confidence.LOW + excludeFilter = file("spotbugs-exclude.xml") +} diff --git a/lib/build.gradle b/lib/build.gradle deleted file mode 100644 index bd372a3d3f..0000000000 --- a/lib/build.gradle +++ /dev/null @@ -1,153 +0,0 @@ -import org.gradle.util.GradleVersion - -plugins { - id 'java-library' - id 'io.github.davidburstrom.version-compatibility' -} -ext.artifactId = project.artifactIdLib -version = rootProject.spotlessChangelog.versionNext -apply from: rootProject.file('gradle/java-setup.gradle') -apply from: rootProject.file('gradle/java-publish.gradle') - -def NEEDS_GLUE = [ - // (alphabetic order please) - 'cleanthat', - 'diktat', - 'flexmark', - 'gherkin', - 'googleJavaFormat', - 'gson', - 'jackson', - 'javaParser', - 'ktfmt', - 'ktlint', - 'lombokStubs', - 'palantirJavaFormat', - 'princeOfSpace', - 'scalafmt', - 'sortPom', - 'tableTestFormatter', - 'zjsonPatch', -] - -for (glue in NEEDS_GLUE) { - sourceSets.register(glue) { - compileClasspath += sourceSets.main.output - runtimeClasspath += sourceSets.main.output - java {} - } -} - -versionCompatibility { - adapters { - // (alphabetic order please) - namespaces.register('Cleanthat') { - versions = [ - '2.1', - ] - targetSourceSetName = 'cleanthat' - } - namespaces.register('KtLint') { - // as discussed at https://github.com/diffplug/spotless/pull/1475 - // we will support no more than 2 breaking changes at a time = 3 incompatible versions - // we will try to drop down to only one version if a stable API can be maintained for a full year - versions = [ - '1.0.0', - ] - targetSourceSetName = 'ktlint' - } - namespaces.register('Diktat') { - versions = [ - '1.2.5', - '2.0.0', - ] - targetSourceSetName = 'diktat' - } - } -} - -tasks.named("check").configure { - dependsOn(tasks.named("testCompatibilityAdapters")) - dependsOn(tasks.named("testCompatibility")) -} - -dependencies { - compileOnly libs.slf4j.api - testCommonImplementation libs.slf4j.api - - // zero runtime reqs is a hard requirements for spotless-lib - // if you need a dep, put it in lib-extra - testCommonImplementation libs.junit.jupiter - testCommonImplementation libs.assertj.core - testCommonImplementation libs.durian.testlib - testCommonImplementation projects.testlib - testCommonRuntimeOnly "org.junit.platform:junit-platform-launcher" - - // GLUE CODE (alphabetic order please) - // cleanthat - cleanthatCompileOnly libs.cleanthat.java - compatCleanthat2Dot1CompileAndTestOnly libs.cleanthat.java - // diktat old supported version 1.x - compatDiktat1Dot2Dot5CompileOnly libs.diktat.rules - // diktat latest supported version 2.x - compatDiktat2Dot0Dot0CompileOnly libs.diktat.runner - // flexmark - flexmarkCompileOnly libs.flexmark.all - // gherkin - gherkinCompileOnly libs.gherkin.utils - gherkinCompileOnly libs.slf4j.api - // googleJavaFormat - googleJavaFormatCompileOnly libs.google.java.format - // gson - gsonCompileOnly libs.gson - // jackson - jacksonCompileOnly libs.jackson.databind - jacksonCompileOnly libs.jackson.dataformat.yaml - // javaParser - javaParserCompileOnly libs.javaparser.symbol.solver.core - // ktfmt - ktfmtCompileOnly libs.ktfmt - ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { - version { - strictly '1.7' // for JDK 8 compatibility - } - } - ktfmtCompileOnly libs.jsr305 - // ktlint latest supported version - compatKtLint1Dot0Dot0CompileAndTestOnly libs.ktlint.rule.engine - compatKtLint1Dot0Dot0CompileAndTestOnly libs.ktlint.ruleset.standard - compatKtLint1Dot0Dot0CompileAndTestOnly libs.slf4j.api - // palantirJavaFormat - palantirJavaFormatCompileOnly libs.palantir.java.format // this version needs to stay compilable against Java 8 for CI Job testNpm - // princeOfSpace - princeOfSpaceCompileOnly libs.prince.of.space.core - // scalafmt - scalafmtCompileOnly libs.scalafmt.core - // sortPom - sortPomCompileOnly libs.sortpom.sorter - sortPomCompileOnly libs.slf4j.api - // tableTestFormatter - tableTestFormatterCompileOnly libs.tabletest.formatter.core - // zjsonPatch - zjsonPatchCompileOnly libs.zjsonpatch -} - -// we'll hold the core lib to a high standard -spotbugs { - // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). - reportLevel = com.github.spotbugs.snom.Confidence.valueOf('LOW') - excludeFilter = file("spotbugs-exclude.xml") -} - -apply from: rootProject.file('gradle/special-tests.gradle') -tasks.withType(Test).configureEach { - jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED" - - failOnNoDiscoveredTests = false -} - -jar { - for (glue in NEEDS_GLUE) { - from sourceSets.getByName(glue).output.classesDirs - } -} diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts new file mode 100644 index 0000000000..942a72b1de --- /dev/null +++ b/lib/build.gradle.kts @@ -0,0 +1,153 @@ +import com.github.spotbugs.snom.Confidence + +plugins { + `java-library` + alias(libs.plugins.version.compatibility) + id("spotless.java-setup") + id("spotless.java-publish") + id("spotless.special-tests") +} + +extra["artifactId"] = property("artifactIdLib") + +version = spotlessChangelog.versionNext + +val needsGlue = + listOf( + // (alphabetic order please) + "cleanthat", + "diktat", + "flexmark", + "gherkin", + "googleJavaFormat", + "gson", + "jackson", + "javaParser", + "ktfmt", + "ktlint", + "lombokStubs", + "palantirJavaFormat", + "princeOfSpace", + "scalafmt", + "sortPom", + "tableTestFormatter", + "zjsonPatch", + ) + +val mainSourceSet = sourceSets.named("main") + +for (glue in needsGlue) { + sourceSets.register(glue) { + compileClasspath += mainSourceSet.get().output + runtimeClasspath += mainSourceSet.get().output + java {} + } +} + +versionCompatibility { + adapters { + // (alphabetic order please) + namespaces.register("Cleanthat") { + versions = listOf("2.1") + targetSourceSetName = "cleanthat" + } + namespaces.register("KtLint") { + // as discussed at https://github.com/diffplug/spotless/pull/1475 + // we will support no more than 2 breaking changes at a time = 3 incompatible versions + // we will try to drop down to only one version if a stable API can be maintained for a full + // year + versions = listOf("1.0.0") + targetSourceSetName = "ktlint" + } + namespaces.register("Diktat") { + versions = listOf("1.2.5", "2.0.0") + targetSourceSetName = "diktat" + } + } +} + +tasks.check { + dependsOn(tasks.named("testCompatibilityAdapters")) + dependsOn(tasks.named("testCompatibility")) +} + +dependencies { + compileOnly(libs.slf4j.api) + "testCommonImplementation"(libs.slf4j.api) + + // zero runtime reqs is a hard requirements for spotless-lib + // if you need a dep, put it in lib-extra + "testCommonImplementation"(libs.junit.jupiter) + "testCommonImplementation"(libs.assertj.core) + "testCommonImplementation"(libs.durian.testlib) + "testCommonImplementation"(projects.testlib) + "testCommonRuntimeOnly"("org.junit.platform:junit-platform-launcher") + + // GLUE CODE (alphabetic order please) + // cleanthat + "cleanthatCompileOnly"(libs.cleanthat.java) + "compatCleanthat2Dot1CompileAndTestOnly"(libs.cleanthat.java) + // diktat old supported version 1.x + "compatDiktat1Dot2Dot5CompileOnly"(libs.diktat.rules) + // diktat latest supported version 2.x + "compatDiktat2Dot0Dot0CompileOnly"(libs.diktat.runner) + // flexmark + "flexmarkCompileOnly"(libs.flexmark.all) + // gherkin + "gherkinCompileOnly"(libs.gherkin.utils) + "gherkinCompileOnly"(libs.slf4j.api) + // googleJavaFormat + "googleJavaFormatCompileOnly"(libs.google.java.format) + // gson + "gsonCompileOnly"(libs.gson) + // jackson + "jacksonCompileOnly"(libs.jackson.databind) + "jacksonCompileOnly"(libs.jackson.dataformat.yaml) + // javaParser + "javaParserCompileOnly"(libs.javaparser.symbol.solver.core) + // ktfmt + "ktfmtCompileOnly"(libs.ktfmt) + "ktfmtCompileOnly"("com.google.googlejavaformat:google-java-format") { + version { + strictly("1.7") // for JDK 8 compatibility + } + } + "ktfmtCompileOnly"(libs.jsr305) + // ktlint latest supported version + "compatKtLint1Dot0Dot0CompileAndTestOnly"(libs.ktlint.rule.engine) + "compatKtLint1Dot0Dot0CompileAndTestOnly"(libs.ktlint.ruleset.standard) + "compatKtLint1Dot0Dot0CompileAndTestOnly"(libs.slf4j.api) + // palantirJavaFormat + "palantirJavaFormatCompileOnly"( + libs.palantir.java.format + ) // this version needs to stay compilable against Java 8 for CI Job testNpm + // princeOfSpace + "princeOfSpaceCompileOnly"(libs.prince.of.space.core) + // scalafmt + "scalafmtCompileOnly"(libs.scalafmt.core) + // sortPom + "sortPomCompileOnly"(libs.sortpom.sorter) + "sortPomCompileOnly"(libs.slf4j.api) + // tableTestFormatter + "tableTestFormatterCompileOnly"(libs.tabletest.formatter.core) + // zjsonPatch + "zjsonPatchCompileOnly"(libs.zjsonpatch) +} + +// we'll hold the core lib to a high standard +spotbugs { + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = Confidence.LOW + excludeFilter = file("spotbugs-exclude.xml") +} + +tasks.withType().configureEach { + jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") + failOnNoDiscoveredTests = false +} + +tasks.jar { + for (glue in needsGlue) { + from(sourceSets.getByName(glue).output.classesDirs) + } +} diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle deleted file mode 100644 index 8f79641d41..0000000000 --- a/plugin-gradle/build.gradle +++ /dev/null @@ -1,94 +0,0 @@ -apply from: rootProject.file('gradle/changelog.gradle') -ext.artifactId = project.artifactIdGradle -version = spotlessChangelog.versionNext -apply plugin: 'java-library' -apply plugin: 'com.gradle.plugin-publish' -apply plugin: 'java-gradle-plugin' -apply from: rootProject.file('gradle/java-setup.gradle') -apply from: rootProject.file('gradle/spotless-freshmark.gradle') - - -dependencies { - if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) { - api projects.lib - api projects.libExtra - } else { - api "com.diffplug.spotless:spotless-lib:${rootProject.spotlessChangelog.versionLast}" - api "com.diffplug.spotless:spotless-lib-extra:${rootProject.spotlessChangelog.versionLast}" - } - implementation libs.durian.core - implementation libs.durian.io - implementation libs.durian.collect - implementation libs.jgit - - testImplementation projects.testlib - testImplementation libs.junit.jupiter - testImplementation libs.assertj.core - testImplementation libs.durian.testlib - testImplementation libs.owasp.encoder - testImplementation libs.solstice - testRuntimeOnly "org.junit.platform:junit-platform-launcher" -} - -apply from: rootProject.file('gradle/special-tests.gradle') -tasks.withType(Test).configureEach { - testLogging.showStandardStreams = true -} -tasks.validatePlugins { - // TODO: https://github.com/gradle/gradle/issues/22600 - enableStricterValidation = true -} - -////////////////////////// -// GRADLE PLUGIN PORTAL // -////////////////////////// -gradlePlugin { - website = "https://github.com/diffplug/spotless" - vcsUrl = "https://github.com/diffplug/spotless" - plugins { - spotlessPlugin { - id = 'com.diffplug.spotless' - implementationClass = 'com.diffplug.gradle.spotless.SpotlessPlugin' - displayName = 'Spotless formatting plugin' - description = project.description - tags.set([ - 'format', - 'style', - 'license', - 'header', - 'google-java-format', - 'eclipse', - 'ktlint', - 'ktfmt', - 'diktat', - 'tsfmt', - 'prettier', - 'scalafmt', - 'scalafix', - 'black', - 'clang-format' - ]) - compatibility { - features { - configurationCache = true - } - } - } - spotlessPluginLegacy { - id = 'com.diffplug.gradle.spotless' - implementationClass = 'com.diffplug.gradle.spotless.SpotlessPluginRedirect' - displayName = 'Spotless formatting plugin (legacy)' - description = project.description - tags.set([ - 'format' - ]) - } - } -} - -tasks.named("publishPlugins") { - enabled = !version.endsWith('-SNAPSHOT') -} - -// have to apply java-publish after setting up the pluginBundle -apply from: rootProject.file('gradle/java-publish.gradle') diff --git a/plugin-gradle/build.gradle.kts b/plugin-gradle/build.gradle.kts new file mode 100644 index 0000000000..b59f4a6f70 --- /dev/null +++ b/plugin-gradle/build.gradle.kts @@ -0,0 +1,94 @@ +import org.gradle.plugin.compatibility.compatibility + +plugins { + `java-library` + `java-gradle-plugin` + alias(libs.plugins.plugin.publish) + id("spotless.changelog") + id("spotless.java-setup") + id("spotless.spotless-freshmark") + id("spotless.special-tests") + // must come after java-gradle-plugin, which is what creates the 'pluginMaven' publication that + // spotless.java-publish then configures + id("spotless.java-publish") +} + +extra["artifactId"] = property("artifactIdGradle") + +version = spotlessChangelog.versionNext + +dependencies { + if ( + version.toString().endsWith("-SNAPSHOT") || + (rootSpotlessChangelog.versionNext == rootSpotlessChangelog.versionLast) + ) { + api(projects.lib) + api(projects.libExtra) + } else { + api("com.diffplug.spotless:spotless-lib:${rootSpotlessChangelog.versionLast}") + api("com.diffplug.spotless:spotless-lib-extra:${rootSpotlessChangelog.versionLast}") + } + implementation(libs.durian.core) + implementation(libs.durian.io) + implementation(libs.durian.collect) + implementation(libs.jgit) + + testImplementation(projects.testlib) + testImplementation(libs.junit.jupiter) + testImplementation(libs.assertj.core) + testImplementation(libs.durian.testlib) + testImplementation(libs.owasp.encoder) + testImplementation(libs.solstice) + testRuntimeOnly("org.junit.platform:junit-platform-launcher") +} + +tasks.withType().configureEach { testLogging.showStandardStreams = true } + +tasks.validatePlugins { + // TODO: https://github.com/gradle/gradle/issues/22600 + enableStricterValidation = true +} + +////////////////////////// +// GRADLE PLUGIN PORTAL // +////////////////////////// +gradlePlugin { + website = "https://github.com/diffplug/spotless" + vcsUrl = "https://github.com/diffplug/spotless" + plugins { + create("spotlessPlugin") { + id = "com.diffplug.spotless" + implementationClass = "com.diffplug.gradle.spotless.SpotlessPlugin" + displayName = "Spotless formatting plugin" + description = project.description + tags = + listOf( + "format", + "style", + "license", + "header", + "google-java-format", + "eclipse", + "ktlint", + "ktfmt", + "diktat", + "tsfmt", + "prettier", + "scalafmt", + "scalafix", + "black", + "clang-format", + ) + compatibility { features { configurationCache = true } } + } + create("spotlessPluginLegacy") { + id = "com.diffplug.gradle.spotless" + implementationClass = "com.diffplug.gradle.spotless.SpotlessPluginRedirect" + displayName = "Spotless formatting plugin (legacy)" + description = project.description + tags = listOf("format") + } + } +} + +tasks.publishPlugins { enabled = !version.toString().endsWith("-SNAPSHOT") } diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle deleted file mode 100644 index 79d9108e80..0000000000 --- a/plugin-maven/build.gradle +++ /dev/null @@ -1,64 +0,0 @@ -import org.gradlex.maven.plugin.development.task.GenerateHelpMojoSourcesTask -import org.gradlex.maven.plugin.development.task.GenerateMavenPluginDescriptorTask - -plugins { - // https://github.com/gradlex-org/maven-plugin-development - alias libs.plugins.maven.plugin.development -} - -apply from: rootProject.file('gradle/changelog.gradle') -ext.artifactId = project.artifactIdMaven -version = spotlessChangelog.versionNext - -apply from: rootProject.file("gradle/java-setup.gradle") -apply from: rootProject.file('gradle/spotless-freshmark.gradle') - -mavenPlugin { - name = 'Spotless Maven Plugin' - artifactId = project.artifactIdMaven - description = project.description -} - -dependencies { - implementation projects.lib - implementation projects.libExtra - - compileOnly libs.maven.plugin.api - compileOnly libs.maven.plugin.annotations - compileOnly libs.maven.core - compileOnly libs.aether.api - - compileOnly libs.jakarta.annotation.api - - implementation libs.durian.core - implementation libs.durian.io - implementation libs.durian.collect - implementation libs.plexus.resources - implementation libs.plexus.utils - implementation libs.jgit - implementation libs.plexus.build.api - - testImplementation project(":testlib") - testImplementation libs.junit.jupiter - testImplementation libs.assertj.core - testImplementation libs.mockito.core - testImplementation libs.durian.io - testImplementation libs.mustache.compiler - testImplementation libs.owasp.encoder - testImplementation libs.maven.plugin.api - testImplementation libs.aether.api - testImplementation libs.plexus.resources - testImplementation libs.maven.core - testRuntimeOnly "org.junit.platform:junit-platform-launcher" -} - -apply from: rootProject.file('gradle/special-tests.gradle') -tasks.withType(Test).configureEach { - systemProperty 'spotlessMavenPluginVersion', project.version - systemProperty 'spotlessProjectDir', "${project.rootProject.projectDir}".toString() - dependsOn 'publishToMavenLocal' - dependsOn ':lib:publishToMavenLocal' - dependsOn ':lib-extra:publishToMavenLocal' -} - -apply from: rootProject.file("gradle/java-publish.gradle") diff --git a/plugin-maven/build.gradle.kts b/plugin-maven/build.gradle.kts new file mode 100644 index 0000000000..1217ec3584 --- /dev/null +++ b/plugin-maven/build.gradle.kts @@ -0,0 +1,59 @@ +plugins { + alias(libs.plugins.maven.plugin.development) + id("spotless.changelog") + id("spotless.java-setup") + id("spotless.spotless-freshmark") + id("spotless.special-tests") + id("spotless.java-publish") +} + +extra["artifactId"] = property("artifactIdMaven") + +version = spotlessChangelog.versionNext + +mavenPlugin { + name = "Spotless Maven Plugin" + artifactId = property("artifactIdMaven").toString() + description = project.description +} + +dependencies { + implementation(projects.lib) + implementation(projects.libExtra) + + compileOnly(libs.maven.plugin.api) + compileOnly(libs.maven.plugin.annotations) + compileOnly(libs.maven.core) + compileOnly(libs.aether.api) + + compileOnly(libs.jakarta.annotation.api) + + implementation(libs.durian.core) + implementation(libs.durian.io) + implementation(libs.durian.collect) + implementation(libs.plexus.resources) + implementation(libs.plexus.utils) + implementation(libs.jgit) + implementation(libs.plexus.build.api) + + testImplementation(projects.testlib) + testImplementation(libs.junit.jupiter) + testImplementation(libs.assertj.core) + testImplementation(libs.mockito.core) + testImplementation(libs.durian.io) + testImplementation(libs.mustache.compiler) + testImplementation(libs.owasp.encoder) + testImplementation(libs.maven.plugin.api) + testImplementation(libs.aether.api) + testImplementation(libs.plexus.resources) + testImplementation(libs.maven.core) + testRuntimeOnly("org.junit.platform:junit-platform-launcher") +} + +tasks.withType().configureEach { + systemProperty("spotlessMavenPluginVersion", project.version) + systemProperty("spotlessProjectDir", "${project.rootProject.projectDir}") + dependsOn(tasks.publishToMavenLocal) + dependsOn(":lib:publishToMavenLocal") + dependsOn(":lib-extra:publishToMavenLocal") +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 7d83f7cafd..0000000000 --- a/settings.gradle +++ /dev/null @@ -1,86 +0,0 @@ -import static java.lang.System.getenv - -pluginManagement { - repositories { - mavenCentral() - gradlePluginPortal() - } -} - -plugins { - id 'com.diffplug.spotless' version '8.10.0' apply false - id 'com.github.spotbugs' version '6.5.11' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.gradle.develocity' version '4.5.0' -} - -dependencyResolutionManagement { - repositories { - mavenCentral() - } -} - -if (System.env['CI'] != null) { - // use the remote buildcache on all CI builds - buildCache { - def cred = { - if (System.env[it] != null) { - return System.env[it] - } else { - return System.getProperty(it) - } - } - remote(HttpBuildCache) { - url = 'https://buildcache.diffplug.com/cache/' - // but we only push if it's a trusted build (not PRs) - String user = cred('buildcacheuser') - String pass = cred('buildcachepass') - if (user != null && pass != null) { - push = true - credentials { - username = user - password = pass - } - } else { - credentials { username = 'anonymous' } - } - } - } -} - -develocity { - buildScan { - termsOfUseUrl = "https://gradle.com/terms-of-service" - termsOfUseAgree = "yes" - publishing { - onlyIf { getenv('CI') != null } - } - } -} - -enableFeaturePreview("STABLE_CONFIGURATION_CACHE") -enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") - -rootProject.name = 'spotless' - -include 'lib' // reusable library with no dependencies -include 'lib-extra' // reusable library with lots of dependencies -include 'plugin-gradle' // gradle-specific glue code -include 'testlib' // library for sharing test infrastructure between the projects below - -def getStartProperty(String name) { - def value = startParameter.getProjectProperties().get(name) - if(null != value) { - return value - } - // user properties are not available in the startParameter - def userPropertiesFile = new File(startParameter.getGradleUserHomeDir(), 'gradle.properties') - def userProperties = new Properties() - if (userPropertiesFile.exists()) { - userProperties.load(userPropertiesFile.newReader()) - } - return userProperties.get(name) -} - -if (!getenv('SPOTLESS_EXCLUDE_MAVEN')?.toBoolean() && !Boolean.valueOf(getStartProperty('SPOTLESS_EXCLUDE_MAVEN') as String)) { - include 'plugin-maven' // maven-specific glue code -} diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000000..956bc4d804 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,87 @@ +pluginManagement { + includeBuild("build-logic") + repositories { + mavenCentral() + gradlePluginPortal() + } +} + +plugins { + id("com.diffplug.spotless") version "8.10.0" apply false + id("com.github.spotbugs") version "6.5.11" apply false + id("com.gradle.develocity") version "4.5.0" +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} + +if (System.getenv("CI") != null) { + // use the remote buildcache on all CI builds + buildCache { + fun cred(name: String): String? = System.getenv(name) ?: System.getProperty(name) + remote { + url = uri("https://buildcache.diffplug.com/cache/") + // but we only push if it's a trusted build (not PRs) + val user = cred("buildcacheuser") + val pass = cred("buildcachepass") + if (user != null && pass != null) { + isPush = true + credentials { + username = user + password = pass + } + } else { + credentials { + username = "anonymous" + } + } + } + } +} + +develocity { + buildScan { + termsOfUseUrl = "https://gradle.com/terms-of-service" + termsOfUseAgree = "yes" + publishing { + onlyIf { System.getenv("CI") != null } + } + } +} + +enableFeaturePreview("STABLE_CONFIGURATION_CACHE") + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + +rootProject.name = "spotless" + +include("lib") // reusable library with no dependencies + +include("lib-extra") // reusable library with lots of dependencies + +include("plugin-gradle") // gradle-specific glue code + +include("testlib") // library for sharing test infrastructure between the projects below + +fun getStartProperty(name: String): String? = + startParameter.projectProperties[name] + ?: File(startParameter.gradleUserHomeDir, "gradle.properties") + .takeIf { it.exists() } + ?.reader() + ?.use { java.util.Properties().apply { load(it) }.getProperty(name) } + +// Groovy's String.toBoolean() -- what this used before the Kotlin DSL migration -- accepts "true", +// "y" and "1", ignoring case. Kotlin's toBoolean() only accepts "true", so the short forms would +// silently become no-ops. +fun String.toBooleanGroovy(): Boolean = trim().lowercase() in setOf("true", "y", "1") + +val excludeMaven = + System.getenv("SPOTLESS_EXCLUDE_MAVEN")?.toBooleanGroovy() == true || + getStartProperty("SPOTLESS_EXCLUDE_MAVEN")?.toBooleanGroovy() == true + +if (!excludeMaven) { + include("plugin-maven") // maven-specific glue code +} diff --git a/testlib/build.gradle b/testlib/build.gradle deleted file mode 100644 index 3cc5fdc3fa..0000000000 --- a/testlib/build.gradle +++ /dev/null @@ -1,43 +0,0 @@ -plugins { - id 'java-library' -} -ext.artifactId = project.artifactIdTestLib -version = rootProject.spotlessChangelog.versionNext -apply from: rootProject.file('gradle/java-setup.gradle') - -dependencies { - api projects.lib - api libs.durian.core - api libs.durian.testlib - api libs.junit.jupiter - api libs.assertj.core - api libs.mockito.core - api libs.selfie.lib - api libs.selfie.runner.junit5 - runtimeOnly "org.junit.platform:junit-platform-launcher" - - implementation libs.durian.io - implementation libs.durian.collect - implementation libs.jgit - implementation gradleTestKit() -} - -// we'll hold the testlib to a low standard (prize brevity) -spotbugs { - // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). - reportLevel = com.github.spotbugs.snom.Confidence.valueOf('HIGH') -} - -apply from: rootProject.file('gradle/special-tests.gradle') -tasks.withType(Test).configureEach { - // for Antlr4FormatterStepTest, KtfmtStepTest, and KtLintStepTest - jvmArgs( - '--add-opens=java.base/java.lang=ALL-UNNAMED', - '--add-opens=java.base/java.util=ALL-UNNAMED', - ) -} - -javadoc { - options.addStringOption('Xdoclint:none', '-quiet') - options.addStringOption('Xwerror', '-quiet') -} diff --git a/testlib/build.gradle.kts b/testlib/build.gradle.kts new file mode 100644 index 0000000000..4956621aa0 --- /dev/null +++ b/testlib/build.gradle.kts @@ -0,0 +1,52 @@ +import com.github.spotbugs.snom.Confidence + +plugins { + `java-library` + id("spotless.java-setup") + id("spotless.special-tests") +} + +extra["artifactId"] = property("artifactIdTestLib") + +version = spotlessChangelog.versionNext + +dependencies { + api(projects.lib) + api(libs.durian.core) + api(libs.durian.testlib) + api(libs.junit.jupiter) + api(libs.assertj.core) + api(libs.mockito.core) + api(libs.selfie.lib) + api(libs.selfie.runner.junit5) + runtimeOnly("org.junit.platform:junit-platform-launcher") + + implementation(libs.durian.io) + implementation(libs.durian.collect) + implementation(libs.jgit) + implementation(gradleTestKit()) +} + +// we'll hold the testlib to a low standard (prize brevity) +spotbugs { + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = Confidence.HIGH +} + +tasks.withType().configureEach { + // for Antlr4FormatterStepTest, KtfmtStepTest, and KtLintStepTest + jvmArgs( + "--add-opens=java.base/java.lang=ALL-UNNAMED", + "--add-opens=java.base/java.util=ALL-UNNAMED", + ) +} + +tasks.withType().configureEach { + options { + (this as? StandardJavadocDocletOptions)?.apply { + encoding = Charsets.UTF_8.name() + addStringOption("Xdoclint:none", "-quiet") + addStringOption("Xwerror", "-quiet") + } + } +}