diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6135ae5 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,34 @@ +name: Publish + +on: + release: + types: [ released ] + workflow_dispatch: + +jobs: + publish: + name: Snapshot build and publish + runs-on: ubuntu-latest + environment: PRODUCTION + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} + steps: + - name: Check out code + uses: actions/checkout@v3.1.0 + + - name: Set up JDK 11 + uses: actions/setup-java@v3.5.1 + with: + distribution: 'zulu' + java-version: 11 + + - name: Grant Permission to Execute Gradle + run: chmod +x gradlew + + - name: Publish to MavenCentral + run: | + ./gradlew publishAllPublicationsToMavenCentral diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 88c702d..59ac329 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -47,5 +47,9 @@ gradlePlugin { id = "sudoklify.kotlin.library" implementationClass = "KotlinLibraryConventionPlugin" } + register("mavenPublishLibrary") { + id = "sudoklify.maven.publish.library" + implementationClass = "MavenPublishLibraryConventionPlugin" + } } } diff --git a/build-logic/convention/src/main/kotlin/MavenPublishLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/MavenPublishLibraryConventionPlugin.kt new file mode 100644 index 0000000..7e89c02 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/MavenPublishLibraryConventionPlugin.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2023 Teogor (Teodor Grigor) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class MavenPublishLibraryConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + pluginManager.apply("com.vanniktech.maven.publish") + } + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 44a2e53..c9273c9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("org.jetbrains.kotlin.jvm") version "1.8.21" + id("com.vanniktech.maven.publish") version "0.25.3" apply false } apply(from = "githooks.gradle.kts") diff --git a/sudoklify/build.gradle.kts b/sudoklify/build.gradle.kts index a261fcf..b67b5c2 100644 --- a/sudoklify/build.gradle.kts +++ b/sudoklify/build.gradle.kts @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import com.vanniktech.maven.publish.SonatypeHost import dev.teogor.sudoklify.buildlogic.BuildInfo plugins { id("sudoklify.kotlin.library") + id("sudoklify.maven.publish.library") } group = BuildInfo.group.fullName @@ -29,3 +31,38 @@ tasks.test { dependencies { testImplementation("junit:junit:4.13.2") } + +@Suppress("UnstableApiUsage") +mavenPublishing { + publishToMavenCentral(SonatypeHost.S01) + + signAllPublications() + + coordinates("dev.teogor.sudoklify", "sudoklify", "1.0.0-alpha01") + + pom { + name.set("Sudoklify") + description.set("Sudoklify stands as a versatile and user-friendly Sudoku puzzle generation library crafted in Kotlin. Effortlessly generate, manipulate, and solve Sudoku puzzles with ease.") + inceptionYear.set("2023") + url.set("https://github.com/teogor/sudoklify/") // Update this URL + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0") + distribution.set("repo") + } + } + developers { + developer { + id.set("teogor") // Update your GitHub username + name.set("Teodor Grigor") // Update your name + url.set("https://github.com/teogor/") + } + } + scm { + url.set("https://github.com/teogor/sudoklify/") // Update this URL + connection.set("scm:git:https://github.com/teogor/sudoklify.git") // Update this connection URL + developerConnection.set("scm:git:git@github.com:teogor/sudoklify.git") // Update this developer connection URL + } + } +}