-
Notifications
You must be signed in to change notification settings - Fork 559
Migrate publishing to com.vanniktech.maven.publish #3052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,9 @@ | ||
| plugins { | ||
| `java-library` | ||
| `maven-publish` | ||
| id("com.vanniktech.maven.publish") | ||
| signing | ||
| } | ||
|
|
||
| java { | ||
| withJavadocJar() | ||
| withSourcesJar() | ||
| } | ||
|
|
||
| tasks.named("sourcesJar") { | ||
| dependsOn(tasks.jar) | ||
| } | ||
|
|
||
| tasks.withType<Javadoc>().configureEach { | ||
| options { | ||
| (this as? StandardJavadocDocletOptions)?.apply { | ||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Goooler marked this conversation as resolved.
|
||
| ) { | ||
| val gpgKey = decode64("ORG_GRADLE_PROJECT_gpg_key64") | ||
| useInMemoryPgpKeys( | ||
| "0x4272C851", | ||
| gpgKey, | ||
| System.getenv("ORG_GRADLE_PROJECT_gpg_passphrase"), | ||
|
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 | ||
| } | ||
|
nedtwigg marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
build-logic/src/main/kotlin/spotless.nexus-publish.gradle.kts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| POM_ARTIFACT_ID=spotless-lib | ||
| POM_NAME=spotless-lib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.