Skip to content

Set up build to publish via Maven Central Portal #4487

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Consult the [Dependency Metadata] section of the [User Guide] for a list of all
of the JUnit Platform, JUnit Jupiter, and JUnit Vintage.

See also <https://repo1.maven.org/maven2/org/junit/> for releases and
<https://oss.sonatype.org/content/repositories/snapshots/org/junit/> for snapshots.
<https://central.sonatype.com/repository/maven-snapshots/org/junit/> for snapshots.


[Codecov]: https://codecov.io/gh/junit-team/junit5
Expand Down
11 changes: 3 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import junitbuild.extensions.dependencyProject

plugins {
alias(libs.plugins.nexusPublish)
id("junitbuild.base-conventions")
id("junitbuild.build-metadata")
id("junitbuild.checkstyle-nohttp")
id("junitbuild.dependency-update-check")
id("junitbuild.jacoco-aggregation-conventions")
id("junitbuild.maven-central-publishing")
id("junitbuild.temp-maven-repo")
}

Expand Down Expand Up @@ -55,10 +57,3 @@ dependencies {
jacocoAggregation(projects.jupiterTests)
jacocoAggregation(projects.platformTests)
}

nexusPublishing {
packageGroup = "org.junit"
repositories {
sonatype()
}
}
5 changes: 5 additions & 0 deletions documentation/documentation.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import junitbuild.exec.CaptureJavaExecOutput
import junitbuild.exec.ClasspathSystemPropertyProvider
import junitbuild.exec.GenerateStandaloneConsoleLauncherShadowedArtifactsFile
import junitbuild.exec.RunConsoleLauncher
import junitbuild.extensions.dependencyProject
import junitbuild.extensions.isSnapshot
import junitbuild.extensions.javaModuleName
import junitbuild.javadoc.ModuleSpecificJavadocFileOption
import org.asciidoctor.gradle.base.AsciidoctorAttributeProvider
import org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask
import org.gradle.api.tasks.PathSensitivity.RELATIVE
import org.ysb33r.grolifant.api.core.jvm.ExecutionMode.JAVA_EXEC

plugins {
alias(libs.plugins.asciidoctorConvert)
Expand Down Expand Up @@ -377,6 +381,7 @@ tasks {
}

asciidoctorPdf {
setExecutionMode(JAVA_EXEC) // Avoid classpath conflicts with other Gradle plugins (e.g. JReleaser)
sources {
include("user-guide/index.adoc")
}
Expand Down
2 changes: 1 addition & 1 deletion documentation/src/docs/asciidoc/link-attributes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ifdef::backend-pdf[]
:javadoc-root: https://junit.org/junit5/docs/{docs-version}/api
endif::[]
// Snapshot Repository
:snapshot-repo: https://oss.sonatype.org/content/repositories/snapshots
:snapshot-repo: https://central.sonatype.com/repository/maven-snapshots
// Base Links
:junit-team: https://github.com/junit-team
:junit5-repo: {junit-team}/junit5
Expand Down
6 changes: 0 additions & 6 deletions gradle/base/code-generator-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
plugins {
`kotlin-dsl`
}

group = "junitbuild.base"

repositories {
gradlePluginPortal()
}
3 changes: 3 additions & 0 deletions gradle/base/dsl-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
`kotlin-dsl`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package junitbuild.extensions

import org.gradle.api.provider.Provider
import org.gradle.plugin.use.PluginDependency

// see https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers
val Provider<PluginDependency>.markerCoordinates: Provider<String>
get() = map { "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" }
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package junitbuild.extensions

import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.VersionCatalog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package junitbuild.extensions

import org.gradle.api.Task
import org.gradle.internal.os.OperatingSystem

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package junitbuild.extensions

fun Any.isSnapshot(): Boolean = toString().contains("SNAPSHOT")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Just a dummy plugin to get the extensions on the classpath of downstream builds
1 change: 1 addition & 0 deletions gradle/base/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group = junitbuild.base
7 changes: 7 additions & 0 deletions gradle/base/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
rootProject.name = "base"

dependencyResolutionManagement {
repositories {
gradlePluginPortal()
}
}

include("code-generator-model")
include("dsl-extensions")
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ develocity = { id = "com.gradle.develocity", version = "4.0" }
foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "0.10.0" }
gitPublish = { id = "org.ajoberstar.git-publish", version = "5.1.1" }
jmh = { id = "me.champeau.jmh", version = "0.7.3" }
jreleaser = { id = "org.jreleaser", version = "1.17.0" }
# check if workaround in gradle.properties can be removed when updating
kotlin = { id = "org.jetbrains.kotlin.jvm", version = "2.1.20" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" }
plantuml = { id = "io.freefair.plantuml", version = "8.13.1" }
shadow = { id = "com.gradleup.shadow", version = "8.3.6" }
spotless = { id = "com.diffplug.spotless", version = "6.25.0" }
Expand Down
1 change: 1 addition & 0 deletions gradle/plugins/code-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
implementation("junitbuild.base:code-generator-model")
implementation("junitbuild.base:dsl-extensions")
implementation(projects.common)
implementation(libs.jackson.dataformat.yaml)
implementation(libs.jackson.module.kotlin)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import junitbuild.extensions.dependencyFromLibs
import junitbuild.generator.GenerateJreRelatedSourceCode

plugins {
Expand Down
8 changes: 4 additions & 4 deletions gradle/plugins/common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import junitbuild.extensions.markerCoordinates

plugins {
`kotlin-dsl`
}

dependencies {
implementation("junitbuild.base:dsl-extensions")
implementation(projects.buildParameters)
implementation(libs.plugins.kotlin.markerCoordinates)
implementation(libs.plugins.bnd.markerCoordinates)
implementation(libs.plugins.commonCustomUserData.markerCoordinates)
implementation(libs.plugins.develocity.markerCoordinates)
implementation(libs.plugins.foojayResolver.markerCoordinates)
implementation(libs.plugins.jmh.markerCoordinates)
implementation(libs.plugins.jreleaser.markerCoordinates)
implementation(libs.plugins.shadow.markerCoordinates)
implementation(libs.plugins.spotless.markerCoordinates)
implementation(libs.plugins.versions.markerCoordinates)
}

// see https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers
val Provider<PluginDependency>.markerCoordinates: Provider<String>
get() = map { "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" }
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import junitbuild.extensions.requiredVersionFromLibs

plugins {
base
checkstyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import junitbuild.extensions.dependencyFromLibs
import junitbuild.extensions.requiredVersionFromLibs

plugins {
id("junitbuild.checkstyle-conventions")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import junitbuild.extensions.requiredVersionFromLibs

plugins {
jacoco
id("junitbuild.build-parameters")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import junitbuild.extensions.javaModuleName
import junitbuild.extensions.isSnapshot
import junitbuild.java.ModuleCompileOptions
import junitbuild.java.ModulePathArgumentProvider
import junitbuild.java.PatchModuleArgumentProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import junitbuild.extensions.requiredVersionFromLibs
import junitbuild.extensions.dependencyFromLibs

plugins {
id("me.champeau.jmh")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import junitbuild.extensions.dependencyFromLibs

plugins {
`java-library`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import junitbuild.extensions.isSnapshot

plugins {
`maven-publish`
signing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import junitbuild.extensions.requiredVersionFromLibs

plugins {
id("com.diffplug.spotless")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import com.gradle.develocity.agent.gradle.internal.test.PredictiveTestSelectionConfigurationInternal
import com.gradle.develocity.agent.gradle.test.PredictiveTestSelectionMode
import junitbuild.extensions.trackOperationSystemAsInput
import junitbuild.extensions.dependencyFromLibs
import junitbuild.extensions.bundleFromLibs
import org.gradle.api.tasks.PathSensitivity.RELATIVE
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.the
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.process.ExecOperations
import trackOperationSystemAsInput
import junitbuild.extensions.trackOperationSystemAsInput
import java.io.ByteArrayOutputStream
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package junitbuild.java

import javaModuleName
import junitbuild.extensions.javaModuleName
import org.gradle.api.Named
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
Expand Down
10 changes: 10 additions & 0 deletions gradle/plugins/publishing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import junitbuild.extensions.markerCoordinates

plugins {
`kotlin-dsl`
}

dependencies {
implementation("junitbuild.base:dsl-extensions")
implementation(libs.plugins.jreleaser.markerCoordinates)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import org.jreleaser.model.Active.RELEASE
import org.jreleaser.model.api.deploy.maven.MavenCentralMavenDeployer.Stage
import java.util.Properties

plugins {
id("org.jreleaser")
id("junitbuild.temp-maven-repo")
}

val tempRepoDir: File by extra

tasks.jreleaserDeploy {
dependsOn("publishAllSubprojectsToTempRepository")
outputs.upToDateWhen { false }
doLast {
val outputProperties = Properties()
layout.buildDirectory.file("jreleaser/output.properties").get().asFile.inputStream().use { input ->
outputProperties.load(input)
}
val deploymentId = outputProperties.getProperty("deploymentId")
if (deploymentId != null) {
println("Deployment ID: $deploymentId")
println("Staging Repo URL: https://central.sonatype.com/api/v1/publisher/deployment/$deploymentId/download")
}
}
}

val mavenCentralUsername = providers.gradleProperty("mavenCentralUsername")
val mavenCentralPassword = providers.gradleProperty("mavenCentralPassword")

jreleaser {
deploy {
maven {
mavenCentral {
register("artifacts") {
active = RELEASE
url = "https://central.sonatype.com/api/v1/publisher"
username = mavenCentralUsername
password = mavenCentralPassword
stagingRepository(tempRepoDir.absolutePath)
applyMavenCentralRules = true
sign = false
checksums = false
namespace = "org.junit"
stage = providers.gradleProperty("jreleaser.mavencentral.stage")
.map(Stage::of)
.orElse(Stage.UPLOAD)
}
}
}
}
}

subprojects {
pluginManager.withPlugin("maven-publish") {
configure<PublishingExtension> {
repositories {
maven {
name = "mavenCentralSnapshots"
url = uri("https://central.sonatype.com/repository/maven-snapshots")
credentials {
username = mavenCentralUsername.orNull
password = mavenCentralPassword.orNull
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ val clearTempRepoDir by tasks.registering {
}
}

val verifyArtifactsInStagingRepositoryAreReproducible by tasks.registering(VerifyBinaryArtifactsAreIdentical::class) {
val publishAllSubprojectsToTempRepository by tasks.registering

tasks.register<VerifyBinaryArtifactsAreIdentical>("verifyArtifactsInStagingRepositoryAreReproducible") {
dependsOn(publishAllSubprojectsToTempRepository)
localRepoDir.set(tempRepoDir)
}

Expand All @@ -32,7 +35,7 @@ subprojects {
publishingTasks.configureEach {
dependsOn(clearTempRepoDir)
}
verifyArtifactsInStagingRepositoryAreReproducible {
publishAllSubprojectsToTempRepository {
dependsOn(publishingTasks)
}
}
Expand Down
11 changes: 9 additions & 2 deletions gradle/plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
pluginManagement {
includeBuild("../base")
}

plugins {
id("junitbuild.dsl-extensions") apply false
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
Expand All @@ -11,10 +19,9 @@ dependencyResolutionManagement {

rootProject.name = "plugins"

includeBuild("../base")

include("build-parameters")
include("common")
include("code-generator")
include("publishing")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
2 changes: 2 additions & 0 deletions junit-jupiter-params/junit-jupiter-params.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import junitbuild.extensions.javaModuleName

plugins {
id("junitbuild.kotlin-library-conventions")
id("junitbuild.shadow-conventions")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import junitbuild.extensions.dependencyProject
import junitbuild.java.WriteArtifactsFile

plugins {
Expand Down
1 change: 1 addition & 0 deletions junit-platform-console/junit-platform-console.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import junitbuild.extensions.javaModuleName
import junitbuild.java.UpdateJarAction

plugins {
Expand Down
2 changes: 2 additions & 0 deletions junit-platform-reporting/junit-platform-reporting.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import junitbuild.extensions.javaModuleName

plugins {
id("junitbuild.java-library-conventions")
id("junitbuild.native-image-properties")
Expand Down
Loading