Skip to content

Commit

Permalink
Converted core to multiplatform project
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Dec 3, 2023
1 parent f5d12e6 commit 43021de
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 55 deletions.
33 changes: 10 additions & 23 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugins {
base
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.gradle.nexusPublish)
`jacoco-report-aggregation`
`git-versioning`
}

Expand All @@ -13,32 +16,16 @@ nexusPublishing {
}
}

dependencies {
subprojects { jacocoAggregation(project) }
}

allprojects {

group = "io.github.gmazzo.codeowners"

plugins.withId("java") {

apply(plugin = "jacoco-report-aggregation")

dependencies {
"testImplementation"(libs.kotlin.test)
"testImplementation"("org.junit.jupiter:junit-jupiter-params")
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
workingDir(provider { temporaryDir })
}

tasks.withType<JacocoReport>().configureEach {
reports.xml.required.set(true)
}

tasks.named("check") {
dependsOn(tasks.withType<JacocoReport>())
}

}
}

tasks.check {
dependsOn(tasks.withType<JacocoReport>())
}
15 changes: 8 additions & 7 deletions buildSrc/src/main/kotlin/maven-central-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
java
`maven-publish`
org.jetbrains.dokka
}
Expand All @@ -19,13 +18,15 @@ if (signingKey != null && signingPassword != null) {
logger.warn("Artifact signing disabled due lack of signing properties `signingKey` and `signingPassword`")
}

java {
withJavadocJar()
withSourcesJar()
}
plugins.withId("java") {
configure<JavaPluginExtension> {
withJavadocJar()
withSourcesJar()
}

tasks.named<Jar>("javadocJar") {
from(tasks.dokkaJavadoc)
tasks.named<Jar>("javadocJar") {
from(tasks.dokkaJavadoc)
}
}

publishing.publications.withType<MavenPublication>().configureEach {
Expand Down
18 changes: 10 additions & 8 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
plugins {
alias(libs.plugins.kotlin.jvm)
`java-test-fixtures`
alias(libs.plugins.kotlin.multiplatform)
`maven-central-publish`
}

description = "CodeOwners Library"

java.toolchain.languageVersion.set(JavaLanguageVersion.of(8))

publishing.publications {
create<MavenPublication>("java") { from(components["java"]) }
kotlin {
jvm()
}

// disables testFixtures artifact publication
components.named<AdhocComponentWithVariants>("java") {
withVariantsFromConfiguration(configurations.testFixturesApiElements.get()) { skip() }
withVariantsFromConfiguration(configurations.testFixturesRuntimeElements.get()) { skip() }
dependencies {
commonTestImplementation(libs.kotlin.test)
commonTestImplementation(platform(libs.junit.bom))
}

publishing.repositories {
maven(layout.buildDirectory.dir("repo")) { name = "Local" }
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import foo.Foo
import foo.bar.FooBar
import foo.bar.impl.FooBarImpl
import foo.impl.FooImpl
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.lang.reflect.Proxy
import kotlin.test.Test
import kotlin.test.assertEquals

class CodeOwnersTest {

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ kotlin = "1.9.21"

[libraries]
jgit = "org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r"
junit-bom = "org.junit:junit-bom:5.8.1"
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }

[plugins]
android = "com.android.application:8.1.4"
buildConfig = "com.github.gmazzo.buildconfig:4.2.0"
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-samWithReceiver = { id = "org.jetbrains.kotlin.plugin.sam.with.receiver", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version = "1.9.10" }
gradle-pluginPublish = { id = "com.gradle.plugin-publish", version = "1.2.1" }
Expand Down
19 changes: 17 additions & 2 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ dependencies {
testImplementation(gradleKotlinDsl())
testRuntimeOnly(plugin(libs.plugins.kotlin.jvm))

pluginUnderTestImplementation(projects.core)
pluginUnderTestImplementation(plugin(libs.plugins.android))
pluginUnderTestImplementation(plugin(libs.plugins.kotlin.jvm))
}

testing.suites.withType<JvmTestSuite> {
useKotlinTest(libs.versions.kotlin)
dependencies {
implementation(platform(libs.junit.bom))
}
targets.all {
testTask {
workingDir(provider { temporaryDir })
}
}
}

gradlePlugin {
website.set("https://github.com/gmazzo/gradle-codeowners-plugin")
vcsUrl.set("https://github.com/gmazzo/gradle-codeowners-plugin")
Expand All @@ -52,7 +63,7 @@ gradlePlugin {
buildConfig {
useKotlinOutput { internalVisibility = true }
buildConfigField("String", "CORE_DEPENDENCY", projects.core.dependencyProject
.publishing.publications.named<MavenPublication>("java").map {
.publishing.publications.named<MavenPublication>("kotlinMultiplatform").map {
"\"${it.groupId}:${it.artifactId}:${it.version}\""
}
)
Expand All @@ -61,6 +72,10 @@ buildConfig {
tasks.integrationTest {
shouldRunAfter(tasks.test)

val core = projects.core.dependencyProject
dependsOn("${core.path}:publishAllPublicationsToLocalRepository")
environment("LOCAL_REPO", core.layout.buildDirectory.dir("repo"))

// AGP 8 requires JDK 17, and we want to be compatible with previous JDKs
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class CodeOwnersPluginITest {
withEnvironment(
mapOf(
"ANDROID_HOME" to System.getenv("ANDROID_HOME"),
"pluginsClasspath" to pluginClasspath.joinToString(separator = File.pathSeparator)
"PLUGINS_CLASSPATH" to pluginClasspath.joinToString(separator = File.pathSeparator),
"LOCAL_REPO" to System.getenv("LOCAL_REPO"),
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/integrationTest/resources/project/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
val pluginsClasspath: String? by System.getenv().withDefault { null }
val PLUGINS_CLASSPATH: String? by System.getenv().withDefault { null }

if (pluginsClasspath == null) {
if (PLUGINS_CLASSPATH == null) {
// meant to allow open this test project as a standalone project
id("com.android.application") version "7.4.0" apply false
kotlin("jvm") version "1.7.21" apply false
Expand Down
13 changes: 4 additions & 9 deletions plugin/src/integrationTest/resources/project/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import java.io.File

val pluginsClasspath: String? by System.getenv().withDefault { null }
val PLUGINS_CLASSPATH: String? by System.getenv().withDefault { null }
val LOCAL_REPO: String? by System.getenv().withDefault { null }

if (pluginsClasspath == null) {
if (PLUGINS_CLASSPATH == null) {
// meant to allow open this test project as a standalone project
pluginManagement {
repositories {
Expand All @@ -19,13 +20,7 @@ dependencyResolutionManagement {
mavenLocal()
mavenCentral()
google()

// allows resolution of the local core dependency added by the plugin
pluginsClasspath?.split(File.pathSeparatorChar)?.let { paths ->
flatDir {
dir(paths.map { file(it).parentFile })
}
}
LOCAL_REPO?.let { maven(File(it)) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositoriesMode = RepositoriesMode.PREFER_PROJECT
repositories {
mavenCentral()
google()
Expand Down

0 comments on commit 43021de

Please sign in to comment.