Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
java-version: 21
- uses: gradle/actions/setup-gradle@v6
- run: ./gradlew spotlessCheck
- run: ./gradlew assemble testClasses
- run: ./gradlew assemble testClasses publishToMavenLocal

build-gradle:
name: Gradle (Java ${{ matrix.jre }}, ${{ matrix.os }})
Expand Down
2 changes: 1 addition & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
implementation(plugin("errorprone"))
implementation(plugin("rewrite"))
implementation(plugin("test-logger"))
implementation(plugin("nexus-publish"))
implementation(plugin("maven-publish"))
implementation(plugin("develocity"))

// TODO: https://github.com/gradle/gradle/issues/15383
Expand Down
180 changes: 36 additions & 144 deletions build-logic/src/main/kotlin/spotless.java-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
plugins {
`java-library`
`maven-publish`
id("com.vanniktech.maven.publish")
Comment thread
Goooler marked this conversation as resolved.
signing
}

java {
withJavadocJar()
withSourcesJar()
}

tasks.named("sourcesJar") {
dependsOn(tasks.jar)
}

tasks.withType<Javadoc>().configureEach {
options {
(this as? StandardJavadocDocletOptions)?.apply {
Expand All @@ -22,160 +13,61 @@ tasks.withType<Javadoc>().configureEach {
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 artifactId = project.findProperty("POM_ARTIFACT_ID")?.toString() ?: project.name
val javadocInfo =
"<h2><a href=\"https://github.com/$org/${rootProject.name}\" style=\"text-transform: none;\">$group:$artifactId:$version</a> by <a href=\"https://www.diffplug.com\" style=\"text-transform: none;\">DiffPlug</a></h2>"
"<h2><a href=\"https://github.com/diffplug/spotless\" style=\"text-transform: none;\">$group:$artifactId:$version</a> by <a href=\"https://www.diffplug.com\" style=\"text-transform: none;\">DiffPlug</a></h2>"
header = javadocInfo

val dotdotGradle = if (project.name.startsWith("eclipse-")) "../../gradle" else "../gradle"
linksOffline("https://docs.gradle.org/6.1.1/javadoc/", "$dotdotGradle/javadoc/gradle")
linksOffline("https://docs.gradle.org/6.1.1/javadoc/", "../gradle/javadoc/gradle")
val versionLast = rootSpotlessChangelog.versionLast
linksOffline(
"https://javadoc.io/static/com.diffplug.spotless/spotless-lib/$versionLast",
"$dotdotGradle/javadoc/spotless-lib",
"../gradle/javadoc/spotless-lib",
)
linksOffline(
"https://javadoc.io/static/com.diffplug.spotless/spotless-lib-extra/$versionLast",
"$dotdotGradle/javadoc/spotless-lib-extra",
"../gradle/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<MavenPublication>("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<String, Map<String, String>>
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") {
signing {
isRequired = false
}
Comment on lines +37 to +40

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still publish to Jitpack? I'd prefer removing it.

} else {
signing {
if (
!project.providers.gradleProperty("signingInMemoryKey").isPresent &&
System.getenv("ORG_GRADLE_PROJECT_gpg_key64") != null
Comment thread
Goooler marked this conversation as resolved.
) {
val gpgKey = decode64("ORG_GRADLE_PROJECT_gpg_key64")
useInMemoryPgpKeys(
"0x4272C851",
gpgKey,
System.getenv("ORG_GRADLE_PROJECT_gpg_passphrase"),
Comment thread
Goooler marked this conversation as resolved.
)
}
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
// find the project with the changelog (this project for plugins, root project for libs)
val changelogProject = if (pluginManager.hasPlugin("spotless.changelog")) 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 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"))
}
}
// ensures that changelog bump and push only happens if the publish was successful
changelogTasks.named("changelogBump") {
dependsOn(tasks.named("publishToMavenCentral"))
// if we have a Gradle plugin, we need to push it up to the plugin portal too
plugins.withId("com.gradle.plugin-publish") {
dependsOn(tasks.named("publishPlugins"))
}
}
}

tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
Comment thread
nedtwigg marked this conversation as resolved.
2 changes: 2 additions & 0 deletions build-logic/src/main/kotlin/spotless.java-setup.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ plugins {
id("spotless.spotless-conventions")
}

group = property("GROUP").toString()

tasks.withType<JavaCompile>().configureEach {
options.encoding = Charsets.UTF_8.name()
options.release = libs.versions.jdk.release.map { it.toInt() }
Expand Down
24 changes: 0 additions & 24 deletions build-logic/src/main/kotlin/spotless.nexus-publish.gradle.kts

This file was deleted.

1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
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")
Expand Down
28 changes: 18 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
org.gradle.kotlin.dsl.allWarningsAsErrors=true

name=spotless
description=Spotless - keep your code spotless with Gradle
org=diffplug

group=com.diffplug.spotless
########## Properties for publishing to Maven Central ##########

artifactIdLib=spotless-lib
artifactIdLibExtra=spotless-lib-extra
artifactIdTestLib=spotless-testlib
mavenCentralPublishing=true
mavenCentralAutomaticPublishing=true
mavenCentralDeploymentValidation=NONE
signAllPublications=true

# naming convention '-maven-plugin' allows mvn 'spotless:check' instead of 'spotless-plugin-maven:check'
artifactIdMaven=spotless-maven-plugin
GROUP=com.diffplug.spotless
POM_DESCRIPTION=Spotless - keep your code spotless with Gradle
Comment thread
Goooler marked this conversation as resolved.
POM_URL=https://github.com/diffplug/spotless
POM_SCM_URL=https://github.com/diffplug/spotless
POM_SCM_CONNECTION=scm:git:https://github.com/diffplug/spotless.git
POM_SCM_DEV_CONNECTION=scm:git:ssh:git@github.com/diffplug/spotless.git

artifactIdGradle=spotless-plugin-gradle
POM_LICENSE_NAME=The Apache Software License, Version 2.0
POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENSE_DIST=repo

POM_DEVELOPER_ID=nedtwigg
POM_DEVELOPER_NAME=Ned Twigg
POM_DEVELOPER_EMAIL=ned.twigg@diffplug.com
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ plugin-publish = "com.gradle.plugin-publish:2.1.1"
equo-ide = "dev.equo.ide:1.7.8"
version-compatibility = "io.github.davidburstrom.version-compatibility:0.5.0"
p2deps = "dev.equo.p2deps:1.7.8"
nexus-publish = "io.github.gradle-nexus.publish-plugin:2.0.0"
maven-publish = "com.vanniktech.maven.publish:0.37.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"
Expand Down
2 changes: 0 additions & 2 deletions lib-extra/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ plugins {
id("spotless.special-tests")
}

extra["artifactId"] = property("artifactIdLibExtra")

version = spotlessChangelog.versionNext

dependencies {
Expand Down
2 changes: 2 additions & 0 deletions lib-extra/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POM_ARTIFACT_ID=spotless-lib-extra
POM_NAME=spotless-lib-extra
2 changes: 0 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ plugins {
id("spotless.special-tests")
}

extra["artifactId"] = property("artifactIdLib")

version = spotlessChangelog.versionNext

val needsGlue =
Expand Down
2 changes: 2 additions & 0 deletions lib/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POM_ARTIFACT_ID=spotless-lib
POM_NAME=spotless-lib
4 changes: 1 addition & 3 deletions plugin-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ plugins {
id("spotless.java-publish")
}

extra["artifactId"] = property("artifactIdGradle")

version = spotlessChangelog.versionNext

dependencies {
Expand Down Expand Up @@ -60,7 +58,7 @@ gradlePlugin {
id = "com.diffplug.spotless"
implementationClass = "com.diffplug.gradle.spotless.SpotlessPlugin"
displayName = "Spotless formatting plugin"
description = project.description
description = property("POM_DESCRIPTION").toString()
tags =
listOf(
"format",
Expand Down
2 changes: 2 additions & 0 deletions plugin-gradle/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POM_ARTIFACT_ID=spotless-plugin-gradle
POM_NAME=spotless-plugin-gradle
4 changes: 2 additions & 2 deletions plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!---freshmark shields
output = [
link(shield('MavenCentral', 'mavencentral', '{{group}}:{{artifactIdMaven}}', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22{{group}}%22%20AND%20a%3A%22{{artifactIdMaven}}%22'),
link(shield('MavenCentral', 'mavencentral', '{{GROUP}}:spotless-maven-plugin', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22{{GROUP}}%22%20AND%20a%3A%22spotless-maven-plugin%22'),
link(shield('Changelog', 'changelog', '{{versionLast}}', 'blue'), 'CHANGES.md'),
link(shield('Javadoc', 'javadoc', 'here', 'blue'), 'https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/{{versionLast}}/index.html')
].join('\n');
Expand All @@ -13,7 +13,7 @@ output = [
<!---freshmark /shields -->

<!---freshmark javadoc
output = prefixDelimiterReplace(input, 'https://{{org}}.github.io/{{name}}/javadoc/spotless-plugin-maven/', '/', versionLast)
output = prefixDelimiterReplace(input, 'https://diffplug.github.io/spotless/javadoc/spotless-plugin-maven/', '/', versionLast)
-->

Spotless is a general-purpose formatting plugin used by [6,000 projects on GitHub (Jan 2023)](https://github.com/search?l=Maven+POM&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. Plugin requires a version of Maven higher or equal to 3.1.0.
Expand Down
Loading
Loading