diff --git a/build.gradle.kts b/build.gradle.kts index 6511936..704a91d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,77 +30,73 @@ allprojects { apply(plugin = "org.jetbrains.kotlin.plugin.serialization") apply(plugin = "org.jetbrains.kotlinx.kover") + apply(plugin = "com.vanniktech.maven.publish") apply(plugin = "org.jetbrains.dokka") apply(plugin = "maven-publish") - apply(plugin = "signing") - - extensions.configure { - repositories { - maven { - val isSnapshot = version.toString().endsWith("SNAPSHOT") - url = uri( - if (!isSnapshot) "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2" - else "https://s01.oss.sonatype.org/content/repositories/snapshots" - ) - - credentials { - username = gradleLocalProperties(rootDir).getProperty("sonatypeUsername") - password = gradleLocalProperties(rootDir).getProperty("sonatypePassword") - } - } - } + extensions.configure { val javadocJar = tasks.register("javadocJar") { dependsOn(tasks.dokkaHtml) archiveClassifier.set("javadoc") from("$buildDir/dokka") } - publications { - withType { - artifact(javadocJar) + mavenPublishing { + artifacts.dokka(javadocJar) + val isSnapshot = version.toString().endsWith("SNAPSHOT") + publishToMavenCentral( + if (isSnapshot) { + SonatypeHost("https://central.sonatype.com/repository/maven-snapshots/") + } else { + SonatypeHost.CENTRAL_PORTAL + } + ) + /** + * IMPORTANT!!! + * Review documentation Vanniktech documentation to properly pass credentials and sign for Central Sonatype + * https://vanniktech.github.io/gradle-maven-publish-plugin/central/#secrets + * If you need an example of implementation, try this: + * ``` + * - name: Publish to MavenCentral + * if: ${{ github.event_name != 'pull_request' }} + * run: ./gradlew publishToMavenCentral --no-configuration-cache + * env: + * ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + * ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + * ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} + * ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + * ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} + * ``` + */ + signAllPublications() + coordinates(group.toString(), project.name, version.toString()) + } - pom { - name.set("KStore") - description.set("A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and okio") - licenses { - license { - name.set("Apache-2.0") - url.set("https://opensource.org/licenses/Apache-2.0") - } - } - url.set("https://xxfast.github.io/KStore/") - issueManagement { - system.set("Github") - url.set("https://github.com/xxfast/KStore/issues") - } - scm { - connection.set("https://github.com/xxfast/KStore.git") - url.set("https://github.com/xxfast/KStore") - } - developers { - developer { - name.set("Isuru Rajapakse") - email.set("isurukusumal36@gmail.com") - } - } + pom { + name = "Kstore" + description = "A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and okio" + url = "https://xxfast.github.io/KStore/" + licenses { + license { + name = "Apache-2.0" + url = "https://opensource.org/licenses/Apache-2.0" + } + } + issueManagement { + system = "Github" + url = "https://github.com/xxfast/KStore/issues" + } + scm { + developerConnection = "scm:git:ssh://git@github.com/xxfast/KStore.git" + connection = "https://github.com/xxfast/KStore.git" + url = "https://github.com/xxfast/KStore" + } + developers { + developer { + name = "Isuru Rajapakse" + email = "isurukusumal36@gmail.com" } } } } - - val publishing = extensions.getByType() - extensions.configure { - useInMemoryPgpKeys( - gradleLocalProperties(rootDir).getProperty("gpgKeySecret"), - gradleLocalProperties(rootDir).getProperty("gpgKeyPassword"), - ) - - sign(publishing.publications) - } - - // TODO: remove after https://youtrack.jetbrains.com/issue/KT-46466 is fixed - project.tasks.withType(AbstractPublishToMaven::class.java).configureEach { - dependsOn(project.tasks.withType(Sign::class.java)) - } }