Skip to content
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

Setup publishing #11

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
27 changes: 27 additions & 0 deletions gradle/plugins/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

plugins {
id("java-gradle-plugin")
alias(libs.plugins.starter.library.kotlin)
}

kotlin {
jvmToolchain(21)
}

def targetJavaVersion = JavaVersion.VERSION_11
tasks.withType(JavaCompile).configureEach {
options.release.set(targetJavaVersion.majorVersion.toInteger())
}
tasks.withType(KotlinCompile).configureEach {
kotlinOptions.jvmTarget = targetJavaVersion
}

gradlePlugin {
plugins {
publishingPlugin {
id = 'com.starter.publishing'
implementationClass = 'PublishingPlugin'
}
}
}
20 changes: 20 additions & 0 deletions gradle/plugins/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import org.gradle.api.initialization.resolve.RepositoriesMode

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
gradlePluginPortal()
google()
}
versionCatalogs {
create("libs") {
from(files("../libs.versions.toml"))
}
}
}

rootProject.name = "plugins"
100 changes: 100 additions & 0 deletions gradle/plugins/src/main/kotlin/PublishingPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
import org.gradle.plugins.signing.SigningExtension

class PublishingPlugin : Plugin<Project> {

override fun apply(target: Project) = with(target) {
pluginManager.apply("maven-publish")
if (findConfig("SIGNING_PASSWORD").isNotEmpty()) {
pluginManager.apply("signing")
}
extensions.configure<PublishingExtension> {
with(repositories) {
maven { maven ->
maven.name = "github"
maven.setUrl("https://maven.pkg.github.com/usefulness/licensee-for-android")
with(maven.credentials) {
username = "usefulness"
password = findConfig("GITHUB_TOKEN")
}
}
maven { maven ->
maven.name = "mavenCentral"
maven.setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
maven.mavenContent { it.releasesOnly() }
with(maven.credentials) {
username = findConfig("OSSRH_USERNAME")
password = findConfig("OSSRH_PASSWORD")
}
}
}
}
pluginManager.withPlugin("com.gradle.plugin-publish") {
extensions.configure<GradlePluginDevelopmentExtension>("gradlePlugin") { gradlePlugin ->
gradlePlugin.apply {
website.set("https://github.com/usefulness/licensee-for-android")
vcsUrl.set("https://github.com/usefulness/licensee-for-android")
}
}
}

pluginManager.withPlugin("signing") {
with(extensions.extraProperties) {
set("signing.keyId", findConfig("SIGNING_KEY_ID"))
set("signing.password", findConfig("SIGNING_PASSWORD"))
set("signing.secretKeyRingFile", findConfig("SIGNING_SECRET_KEY_RING_FILE"))
}

extensions.configure<SigningExtension>("signing") { signing ->
signing.sign(extensions.getByType(PublishingExtension::class.java).publications)
}
}

pluginManager.withPlugin("java") {
extensions.configure<JavaPluginExtension> {
withSourcesJar()
}
extensions.configure<PublishingExtension> {
publications.configureEach { publication ->
(publication as? MavenPublication)?.pom { pom ->
pom.name.set("${project.group}:${project.name}")
pom.description.set(project.description)
pom.url.set("https://github.com/usefulness/licensee-for-android")
pom.licenses { licenses ->
licenses.license { license ->
license.name.set("The MIT License")
license.url.set("https://github.com/usefulness/licensee-for-android/blob/master/LICENSE")
}
}
pom.developers { developers ->
developers.developer { developer ->
developer.id.set("mateuszkwiecinski")
developer.name.set("Mateusz Kwiecinski")
developer.email.set("[email protected]")
}
}
pom.scm { scm ->
scm.connection.set("scm:git:github.com/usefulness/licensee-for-android.git")
scm.developerConnection.set("scm:git:ssh://github.com/usefulness/licensee-for-android.git")
scm.url.set("https://github.com/usefulness/licensee-for-android/tree/master")
}
}
}
}
}
}

private inline fun <reified T> ExtensionContainer.configure(crossinline receiver: T.() -> Unit) {
configure(T::class.java) { receiver(it) }
}
}

private fun Project.findConfig(key: String): String {
return findProperty(key)?.toString() ?: System.getenv(key) ?: ""
}
1 change: 1 addition & 0 deletions licensee-for-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.starter.library.kotlin)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotlinx.binarycompatibility)
id("com.starter.publishing")
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ dependencyResolutionManagement {
mavenCentral()
}
}

rootProject.name = "io.github.usefulness"

include("licensee-for-android")
//include("ui")
//include("core")
includeBuild("gradle/plugins")