From dc5d52967bb29ac28aaec8c30fe4b7c8c901ac22 Mon Sep 17 00:00:00 2001 From: William Date: Mon, 9 Nov 2026 08:08:51 -0800 Subject: [PATCH] Publish to Maven Central from GitHub Releases - Add the com.vanniktech.maven.publish plugin with POM metadata (GPL-3.0, SCM, developer) and Central Portal publishing. - Version comes from -PreleaseVersion (the release tag); local builds are 1.3-SNAPSHOT. Signing only runs when a key is provided. - release.yml publishes to Central and attaches fastjavaio.jar when a GitHub Release is published; ci.yml runs tests on pushes and PRs. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 18 +++++++++++++ .github/workflows/release.yml | 41 ++++++++++++++++++++++++++++++ build.gradle | 48 ++++++++++++++++++++++++++++++----- 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..076281c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + - uses: gradle/actions/setup-gradle@v5 + - run: ./gradlew test javadoc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..097d949 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: Release + +# Publishing a GitHub Release (e.g. tag "1.3") publishes that version to +# Maven Central and attaches fastjavaio.jar to the release. +on: + release: + types: [published] + +permissions: + contents: write # upload the jar to the release + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + - uses: gradle/actions/setup-gradle@v5 + + - name: Determine version from tag + id: version + run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" + + - name: Test + run: ./gradlew test -PreleaseVersion=${{ steps.version.outputs.version }} + + - name: Publish to Maven Central + run: ./gradlew publishToMavenCentral makeJar -PreleaseVersion=${{ steps.version.outputs.version }} + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }} + + - name: Attach fastjavaio.jar to the release + run: gh release upload "$GITHUB_REF_NAME" fastjavaio.jar --clobber + env: + GH_TOKEN: ${{ github.token }} diff --git a/build.gradle b/build.gradle index fd8f06c..7580dcf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,11 @@ plugins { id 'java-library' + id 'com.vanniktech.maven.publish' version '0.37.0' } group = 'io.github.williamfiset' -version = '1.2' +// Release builds pass -PreleaseVersion=; local builds are snapshots. +version = providers.gradleProperty('releaseVersion').getOrElse('1.3-SNAPSHOT') repositories { mavenCentral() @@ -14,11 +16,6 @@ dependencies { testImplementation 'junit:junit:4.13.2' } -java { - withSourcesJar() - withJavadocJar() -} - // Compile against the Java 8 API so the jar runs on any judge or JVM from Java 8 onward. tasks.withType(JavaCompile).configureEach { options.release = 8 @@ -51,3 +48,42 @@ tasks.register('makeJar') { java.nio.file.StandardCopyOption.REPLACE_EXISTING) } } + +// Maven Central publishing (sources and javadoc jars are added by the plugin). +// Credentials come from Gradle properties / ORG_GRADLE_PROJECT_* env vars: +// mavenCentralUsername, mavenCentralPassword, signingInMemoryKey, signingInMemoryKeyPassword +mavenPublishing { + publishToMavenCentral(true) // true = release automatically once validation passes + // Central requires signatures; skip signing for local builds that have no key. + if (providers.gradleProperty('signingInMemoryKey').isPresent()) { + signAllPublications() + } + + coordinates(project.group.toString(), 'fastjavaio', project.version.toString()) + + pom { + name = 'FastJavaIO' + description = 'A lightweight, dependency-free, fast input reader for Java.' + inceptionYear = '2017' + url = 'https://github.com/williamfiset/FastJavaIO' + licenses { + license { + name = 'GNU General Public License v3.0' + url = 'https://www.gnu.org/licenses/gpl-3.0.txt' + distribution = 'repo' + } + } + developers { + developer { + id = 'williamfiset' + name = 'William Fiset' + url = 'https://github.com/williamfiset' + } + } + scm { + url = 'https://github.com/williamfiset/FastJavaIO' + connection = 'scm:git:git://github.com/williamfiset/FastJavaIO.git' + developerConnection = 'scm:git:ssh://git@github.com/williamfiset/FastJavaIO.git' + } + } +}