From b3285bb68768b21414f9e28a9d6da2cc1882c3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kwiecin=CC=81ski?= Date: Sun, 23 Jun 2024 16:46:35 +0200 Subject: [PATCH] Base, jvm-only mulitplatform setup --- .github/workflows/on-pull-request.yml | 8 +- gradle/libs.versions.toml | 2 + gradle/plugins/build.gradle | 5 + gradle/plugins/settings.gradle | 4 - .../src/main/kotlin/PublishingPlugin.kt | 112 +++++++++--------- issuechecker/build.gradle | 45 ++++--- .../com/starter/issuechecker/CheckResult.kt | 0 .../starter/issuechecker/DefaultChecker.kt | 0 .../kotlin/com/starter/issuechecker/Di.kt | 0 .../com/starter/issuechecker/IssueChecker.kt | 0 .../issuechecker/resolvers/StatusResolver.kt | 0 .../resolvers/github/GithubStatusResolver.kt | 0 .../youtrack/YoutrackStatusResolver.kt | 0 .../issuechecker/DefaultCheckerTest.kt | 0 .../com/starter/issuechecker/Factories.kt | 0 .../starter/issuechecker/FunctionalTest.kt | 0 .../com/starter/issuechecker/ResourceUtils.kt | 0 .../github/GithubStatusResolverTest.kt | 0 .../youtrack/YoutrackStatusResolverTest.kt | 0 .../{test => jvmTest}/resources/github.json | 0 .../{test => jvmTest}/resources/youtrack.json | 0 settings.gradle | 1 - 22 files changed, 91 insertions(+), 86 deletions(-) rename issuechecker/src/{main => commonMain}/kotlin/com/starter/issuechecker/CheckResult.kt (100%) rename issuechecker/src/{main => commonMain}/kotlin/com/starter/issuechecker/DefaultChecker.kt (100%) rename issuechecker/src/{main => commonMain}/kotlin/com/starter/issuechecker/Di.kt (100%) rename issuechecker/src/{main => commonMain}/kotlin/com/starter/issuechecker/IssueChecker.kt (100%) rename issuechecker/src/{main => commonMain}/kotlin/com/starter/issuechecker/resolvers/StatusResolver.kt (100%) rename issuechecker/src/{main => commonMain}/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolver.kt (100%) rename issuechecker/src/{main => commonMain}/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolver.kt (100%) rename issuechecker/src/{test => jvmTest}/kotlin/com/starter/issuechecker/DefaultCheckerTest.kt (100%) rename issuechecker/src/{test => jvmTest}/kotlin/com/starter/issuechecker/Factories.kt (100%) rename issuechecker/src/{test => jvmTest}/kotlin/com/starter/issuechecker/FunctionalTest.kt (100%) rename issuechecker/src/{test => jvmTest}/kotlin/com/starter/issuechecker/ResourceUtils.kt (100%) rename issuechecker/src/{test => jvmTest}/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolverTest.kt (100%) rename issuechecker/src/{test => jvmTest}/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolverTest.kt (100%) rename issuechecker/src/{test => jvmTest}/resources/github.json (100%) rename issuechecker/src/{test => jvmTest}/resources/youtrack.json (100%) diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml index c775f9a..0bec22e 100644 --- a/.github/workflows/on-pull-request.yml +++ b/.github/workflows/on-pull-request.yml @@ -59,10 +59,6 @@ jobs: - run: git diff --exit-code - - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - - uses: actions/upload-artifact@v4 if: ${{ always() }} with: @@ -98,7 +94,7 @@ jobs: path: diffuse-source-file key: diffuse-${{ github.sha }} - - run: find . -regex ".*issuechecker/build/libs/issuechecker-[0-9SNAPSHOT\.-]*\.jar" -print | xargs -n 1 -I % cp % diffuse-source-file + - run: find . -regex ".*issuechecker/build/libs/issuechecker-jvm-[0-9SNAPSHOT\.-]*\.jar" -print | xargs -n 1 -I % cp % diffuse-source-file if: github.event_name != 'pull_request' shell: bash @@ -109,7 +105,7 @@ jobs: path: diffuse-source-file key: diffuse-${{ github.event.pull_request.base.sha }} - - run: find . -regex ".*issuechecker/build/libs/issuechecker-[0-9SNAPSHOT\.-]*\.jar" -print | xargs -n 1 -I % cp % pull-request-artifact.jar + - run: find . -regex ".*issuechecker/build/libs/issuechecker-jvm-[0-9SNAPSHOT\.-]*\.jar" -print | xargs -n 1 -I % cp % pull-request-artifact.jar if: github.event_name == 'pull_request' shell: bash diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0f004e4..f473ad2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -39,6 +39,8 @@ osacky-gradledoctor = { id = "com.osacky.doctor", version.ref = "gradle-gradledo kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "mavencentral-kotlin" } starter-config = { id = "com.starter.config", version.ref = "gradle-starter" } starter-library-kotlin = { id = "com.starter.library.kotlin", version.ref = "gradle-starter" } +starter-library-multiplatform = { id = "com.starter.library.multiplatform", version.ref = "gradle-starter" } starter-versioning = { id = "com.starter.versioning", version.ref = "gradle-starter" } johnrengelman-shadow = { id = "com.github.johnrengelman.shadow", version.ref = "gradle-johnrengelman-shadow" } kotlinx-binarycompatibility = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "maven-binarycompatiblity" } +kotlin-samwithreceiver = { id = "org.jetbrains.kotlin.plugin.sam.with.receiver", version.ref = "mavencentral-kotlin" } diff --git a/gradle/plugins/build.gradle b/gradle/plugins/build.gradle index 6cf8fa0..31aeff9 100644 --- a/gradle/plugins/build.gradle +++ b/gradle/plugins/build.gradle @@ -1,6 +1,11 @@ plugins { id 'java-gradle-plugin' alias(libs.plugins.starter.library.kotlin) + alias(libs.plugins.kotlin.samwithreceiver) +} + +samWithReceiver { + annotation("org.gradle.api.HasImplicitReceiver") } dependencies { diff --git a/gradle/plugins/settings.gradle b/gradle/plugins/settings.gradle index 02f493b..426ae25 100644 --- a/gradle/plugins/settings.gradle +++ b/gradle/plugins/settings.gradle @@ -1,9 +1,5 @@ import org.gradle.api.initialization.resolve.RepositoriesMode -plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" -} - dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { diff --git a/gradle/plugins/src/main/kotlin/PublishingPlugin.kt b/gradle/plugins/src/main/kotlin/PublishingPlugin.kt index 8d7dffd..bd5707e 100644 --- a/gradle/plugins/src/main/kotlin/PublishingPlugin.kt +++ b/gradle/plugins/src/main/kotlin/PublishingPlugin.kt @@ -1,13 +1,13 @@ 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.api.tasks.TaskProvider import org.gradle.jvm.tasks.Jar import org.gradle.plugins.signing.SigningExtension import org.jetbrains.dokka.gradle.DokkaTask +@Suppress("unused") class PublishingPlugin : Plugin { override fun apply(target: Project) = with(target) { @@ -16,77 +16,79 @@ class PublishingPlugin : Plugin { pluginManager.apply("signing") } - extensions.configure { - withSourcesJar() - withJavadocJar() - } - - pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { pluginManager.apply("org.jetbrains.dokka") - tasks.withType(DokkaTask::class.java).configureEach { dokkaTask -> - dokkaTask.notCompatibleWithConfigurationCache("https://github.com/Kotlin/dokka/issues/1217") + tasks.withType(DokkaTask::class.java).configureEach { + notCompatibleWithConfigurationCache("https://github.com/Kotlin/dokka/issues/1217") } - tasks.named("javadocJar", Jar::class.java) { javadocJar -> - javadocJar.from(tasks.named("dokkaJavadoc")) + + tasks.register("javadocJar", Jar::class.java) { + archiveClassifier.set("javadoc") + from(tasks.named("dokkaJavadoc")) } } - extensions.configure { - with(repositories) { - maven { maven -> - maven.name = "github" - maven.setUrl("https://maven.pkg.github.com/usefulness/issuechecker") - with(maven.credentials) { + extensions.configure(PublishingExtension::class.java) { + repositories { + maven { + name = "github" + setUrl("https://maven.pkg.github.com/usefulness/issuechecker") + credentials { username = "usefulness" password = findConfig("GITHUB_TOKEN") } } - maven { maven -> - maven.name = "mavenCentral" - maven.setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2/") - maven.mavenContent { it.releasesOnly() } - with(maven.credentials) { + maven { + name = "mavenCentral" + setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + mavenContent { releasesOnly() } + credentials { username = findConfig("OSSRH_USERNAME") password = findConfig("OSSRH_PASSWORD") } } - maven { maven -> - maven.name = "mavenCentralSnapshot" - maven.setUrl("https://oss.sonatype.org/content/repositories/snapshots") - maven.mavenContent { it.snapshotsOnly() } - with(maven.credentials) { + maven { + name = "mavenCentralSnapshot" + setUrl("https://oss.sonatype.org/content/repositories/snapshots") + mavenContent { snapshotsOnly() } + credentials { username = findConfig("OSSRH_USERNAME") password = findConfig("OSSRH_PASSWORD") } } } - with(publications) { - register("mavenJava", MavenPublication::class.java) { publication -> - publication.from(components.getByName("java")) - publication.pom { pom -> - pom.name.set("${project.group}:${project.name}") - pom.description.set("A tool that scans sources for all resolved links to public trackers") - pom.url.set("https://github.com/usefulness/issuechecker") - pom.licenses { licenses -> - licenses.license { license -> - license.name.set("MIT") - license.url.set("https://github.com/usefulness/issuechecker/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") - } + publications.named { it == "jvm" }.configureEach { + this as MavenPublication + artifact(tasks.named("javadocJar")) + } + publications.configureEach { + if (this !is MavenPublication) { + return@configureEach + } + + pom { + name.set("${project.group}:${project.name}") + description.set("A tool that scans sources for all resolved links to public trackers") + url.set("https://github.com/usefulness/issuechecker") + licenses { + license { + name.set("MIT") + url.set("https://github.com/usefulness/issuechecker/blob/master/LICENSE") } - pom.scm { scm -> - scm.connection.set("scm:git:github.com/usefulness/issuechecker.git") - scm.developerConnection.set("scm:git:ssh://github.com/usefulness/issuechecker.git") - scm.url.set("https://github.com/usefulness/issuechecker/tree/master") + } + developers { + developer { + id.set("mateuszkwiecinski") + name.set("Mateusz Kwiecinski") + email.set("36954793+mateuszkwiecinski@users.noreply.github.com") } } + scm { + connection.set("scm:git:github.com/usefulness/issuechecker.git") + developerConnection.set("scm:git:ssh://github.com/usefulness/issuechecker.git") + url.set("https://github.com/usefulness/issuechecker/tree/master") + } } } } @@ -97,15 +99,11 @@ class PublishingPlugin : Plugin { set("signing.secretKeyRingFile", findConfig("SIGNING_SECRET_KEY_RING_FILE")) } - extensions.configure("signing") { signing -> - signing.sign(extensions.getByType(PublishingExtension::class.java).publications) + extensions.configure("signing") { + sign(extensions.getByType(PublishingExtension::class.java).publications) } } } - - private inline fun ExtensionContainer.configure(crossinline receiver: T.() -> Unit) { - configure(T::class.java) { receiver(it) } - } } private fun Project.findConfig(key: String): String { diff --git a/issuechecker/build.gradle b/issuechecker/build.gradle index 5467aa1..09b7d9a 100644 --- a/issuechecker/build.gradle +++ b/issuechecker/build.gradle @@ -1,10 +1,10 @@ plugins { - alias(libs.plugins.starter.library.kotlin) + alias(libs.plugins.starter.library.multiplatform) alias(libs.plugins.kotlin.serialization) id 'com.starter.publishing' } -tasks.named("test") { +tasks.withType(Test).configureEach { useJUnitPlatform() testLogging { events "skipped", "failed" @@ -12,22 +12,31 @@ tasks.named("test") { } kotlin { + jvm() + explicitApi() + sourceSets { + commonMain.dependencies { + implementation(libs.coroutines.core) + implementation(libs.okio.core) + implementation(libs.kotlinx.serialization.json) + implementation(project.dependencies.platform(libs.retrofit.bom)) + } + jvmMain.dependencies { + api(libs.okhttp.core) + implementation(libs.retrofit.core) + implementation(libs.retrofit.converter.kotlinxserialization) + } + commonTest.dependencies { + implementation(kotlin("test")) + } + jvmTest.dependencies { + runtimeOnly(libs.junit.platform.launcher) + implementation(libs.coroutines.test) + implementation(libs.okhttp.mockwebserver) + implementation(libs.assertj.core) + implementation(libs.junit.jupiter.api) + } + } } -dependencies { - implementation(libs.coroutines.core) - api(libs.okhttp.core) - implementation(libs.okio.core) - implementation(libs.kotlinx.serialization.json) - implementation(platform(libs.retrofit.bom)) - implementation(libs.retrofit.core) - implementation(libs.retrofit.converter.kotlinxserialization) - - testRuntimeOnly(libs.junit.platform.launcher) - - testImplementation(libs.coroutines.test) - testImplementation(libs.okhttp.mockwebserver) - testImplementation(libs.assertj.core) - testImplementation(libs.junit.jupiter.api) -} diff --git a/issuechecker/src/main/kotlin/com/starter/issuechecker/CheckResult.kt b/issuechecker/src/commonMain/kotlin/com/starter/issuechecker/CheckResult.kt similarity index 100% rename from issuechecker/src/main/kotlin/com/starter/issuechecker/CheckResult.kt rename to issuechecker/src/commonMain/kotlin/com/starter/issuechecker/CheckResult.kt diff --git a/issuechecker/src/main/kotlin/com/starter/issuechecker/DefaultChecker.kt b/issuechecker/src/commonMain/kotlin/com/starter/issuechecker/DefaultChecker.kt similarity index 100% rename from issuechecker/src/main/kotlin/com/starter/issuechecker/DefaultChecker.kt rename to issuechecker/src/commonMain/kotlin/com/starter/issuechecker/DefaultChecker.kt diff --git a/issuechecker/src/main/kotlin/com/starter/issuechecker/Di.kt b/issuechecker/src/commonMain/kotlin/com/starter/issuechecker/Di.kt similarity index 100% rename from issuechecker/src/main/kotlin/com/starter/issuechecker/Di.kt rename to issuechecker/src/commonMain/kotlin/com/starter/issuechecker/Di.kt diff --git a/issuechecker/src/main/kotlin/com/starter/issuechecker/IssueChecker.kt b/issuechecker/src/commonMain/kotlin/com/starter/issuechecker/IssueChecker.kt similarity index 100% rename from issuechecker/src/main/kotlin/com/starter/issuechecker/IssueChecker.kt rename to issuechecker/src/commonMain/kotlin/com/starter/issuechecker/IssueChecker.kt diff --git a/issuechecker/src/main/kotlin/com/starter/issuechecker/resolvers/StatusResolver.kt b/issuechecker/src/commonMain/kotlin/com/starter/issuechecker/resolvers/StatusResolver.kt similarity index 100% rename from issuechecker/src/main/kotlin/com/starter/issuechecker/resolvers/StatusResolver.kt rename to issuechecker/src/commonMain/kotlin/com/starter/issuechecker/resolvers/StatusResolver.kt diff --git a/issuechecker/src/main/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolver.kt b/issuechecker/src/commonMain/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolver.kt similarity index 100% rename from issuechecker/src/main/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolver.kt rename to issuechecker/src/commonMain/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolver.kt diff --git a/issuechecker/src/main/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolver.kt b/issuechecker/src/commonMain/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolver.kt similarity index 100% rename from issuechecker/src/main/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolver.kt rename to issuechecker/src/commonMain/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolver.kt diff --git a/issuechecker/src/test/kotlin/com/starter/issuechecker/DefaultCheckerTest.kt b/issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/DefaultCheckerTest.kt similarity index 100% rename from issuechecker/src/test/kotlin/com/starter/issuechecker/DefaultCheckerTest.kt rename to issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/DefaultCheckerTest.kt diff --git a/issuechecker/src/test/kotlin/com/starter/issuechecker/Factories.kt b/issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/Factories.kt similarity index 100% rename from issuechecker/src/test/kotlin/com/starter/issuechecker/Factories.kt rename to issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/Factories.kt diff --git a/issuechecker/src/test/kotlin/com/starter/issuechecker/FunctionalTest.kt b/issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/FunctionalTest.kt similarity index 100% rename from issuechecker/src/test/kotlin/com/starter/issuechecker/FunctionalTest.kt rename to issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/FunctionalTest.kt diff --git a/issuechecker/src/test/kotlin/com/starter/issuechecker/ResourceUtils.kt b/issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/ResourceUtils.kt similarity index 100% rename from issuechecker/src/test/kotlin/com/starter/issuechecker/ResourceUtils.kt rename to issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/ResourceUtils.kt diff --git a/issuechecker/src/test/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolverTest.kt b/issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolverTest.kt similarity index 100% rename from issuechecker/src/test/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolverTest.kt rename to issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/resolvers/github/GithubStatusResolverTest.kt diff --git a/issuechecker/src/test/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolverTest.kt b/issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolverTest.kt similarity index 100% rename from issuechecker/src/test/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolverTest.kt rename to issuechecker/src/jvmTest/kotlin/com/starter/issuechecker/resolvers/youtrack/YoutrackStatusResolverTest.kt diff --git a/issuechecker/src/test/resources/github.json b/issuechecker/src/jvmTest/resources/github.json similarity index 100% rename from issuechecker/src/test/resources/github.json rename to issuechecker/src/jvmTest/resources/github.json diff --git a/issuechecker/src/test/resources/youtrack.json b/issuechecker/src/jvmTest/resources/youtrack.json similarity index 100% rename from issuechecker/src/test/resources/youtrack.json rename to issuechecker/src/jvmTest/resources/youtrack.json diff --git a/settings.gradle b/settings.gradle index 5a16624..d929e03 100644 --- a/settings.gradle +++ b/settings.gradle @@ -9,7 +9,6 @@ pluginManagement { } plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" id("com.gradle.develocity") version "3.17.5" }