diff --git a/gradle/plugins/build.gradle b/gradle/plugins/build.gradle new file mode 100644 index 0000000..0aab13a --- /dev/null +++ b/gradle/plugins/build.gradle @@ -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' + } + } +} diff --git a/gradle/plugins/settings.gradle b/gradle/plugins/settings.gradle new file mode 100644 index 0000000..54efe2f --- /dev/null +++ b/gradle/plugins/settings.gradle @@ -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" diff --git a/gradle/plugins/src/main/kotlin/PublishingPlugin.kt b/gradle/plugins/src/main/kotlin/PublishingPlugin.kt new file mode 100644 index 0000000..e43dc81 --- /dev/null +++ b/gradle/plugins/src/main/kotlin/PublishingPlugin.kt @@ -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 { + + override fun apply(target: Project) = with(target) { + pluginManager.apply("maven-publish") + if (findConfig("SIGNING_PASSWORD").isNotEmpty()) { + pluginManager.apply("signing") + } + extensions.configure { + 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("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("signing") { signing -> + signing.sign(extensions.getByType(PublishingExtension::class.java).publications) + } + } + + pluginManager.withPlugin("java") { + extensions.configure { + withSourcesJar() + } + extensions.configure { + 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("36954793+mateuszkwiecinski@users.noreply.github.com") + } + } + 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 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) ?: "" +} diff --git a/licensee-for-android/build.gradle b/licensee-for-android/build.gradle index 6c8be67..7898231 100644 --- a/licensee-for-android/build.gradle +++ b/licensee-for-android/build.gradle @@ -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 { diff --git a/settings.gradle b/settings.gradle index 020d2de..1149132 100644 --- a/settings.gradle +++ b/settings.gradle @@ -19,8 +19,8 @@ dependencyResolutionManagement { mavenCentral() } } + rootProject.name = "io.github.usefulness" include("licensee-for-android") -//include("ui") -//include("core") +includeBuild("gradle/plugins")