Skip to content

Commit

Permalink
Try to improve the gradle structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdvrieze committed Jun 11, 2024
1 parent eccc5d0 commit 8e82608
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 3,181 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ repositories {
```

### Core
#### multiplatform
#### multiplatform (will default to multiplatform implementation for JVM/Android)
```
implementation("io.github.pdvrieze.xmlutil:core:0.90.1-SNAPSHOT")
```
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions core/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import org.gradle.api.attributes.java.TargetJvmEnvironment.TARGET_JVM_ENVIRONMEN
plugins {
id("projectPlugin")
kotlin("jvm")
alias(libs.plugins.kotlinSerialization)
`java-library`
`maven-publish`
signing
alias(libs.plugins.dokka)
Expand All @@ -39,7 +37,7 @@ base {
archivesName = "core-android"
}

val autoModuleName = "net.devrieze.xmlutil.core"
val autoModuleName = "net.devrieze.xmlutil.core.android"

kotlin {
explicitApi()
Expand All @@ -64,7 +62,7 @@ kotlin {

dependencies {
compileOnly(libs.kxml2)
api(project(":core:base"))
api(projects.core)

testImplementation(kotlin("test-junit5"))
testImplementation(libs.junit5.api)
Expand Down
1,469 changes: 0 additions & 1,469 deletions core/base/api/base.api

This file was deleted.

1,648 changes: 0 additions & 1,648 deletions core/base/api/base.klib.api

This file was deleted.

15 changes: 4 additions & 11 deletions core/base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ plugins {
alias(libs.plugins.binaryValidator)
}

base {
archivesName = "core"
}

config {
applyLayout = false
}
Expand Down Expand Up @@ -122,12 +118,9 @@ kotlin {
targets.all {
val targetName = name
mavenPublication {
val newId = when (targetName) {
"jvm" -> "core-jvmCommon"
else -> artifactId.replace("base", "core")
when (targetName) {
"jvm" -> artifactId = "core-jvmCommon"
}
logger.lifecycle("Renamed artefact for $targetName from $artifactId to $newId")
artifactId = newId
}
@Suppress("OPT_IN_USAGE")
when (val t = this) {
Expand All @@ -148,8 +141,8 @@ kotlin {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-annotations-common"))
implementation(project(":testutil"))
implementation(project(":serialization"))
implementation(projects.testutil)
implementation(projects.serialization)
}
}

Expand Down
39 changes: 11 additions & 28 deletions core/compat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,27 @@ plugins {
idea
}

base {
archivesName = "compat"
}

val autoModuleName = "net.devrieze.xmlutil.core"
val autoModuleName = "net.devrieze.xmlutil.core.compat"

kotlin {
explicitApi()
applyDefaultXmlUtilHierarchyTemplate()

val testTask = tasks.create("test") {
group = "verification"
}
val cleanTestTask = tasks.create("cleanTest") {
group = "verification"
}

jvm("jdk") {
mavenPublication {
artifactId = "compat-jdk"
artifactId = "core-compat-jdk"
}
}
jvm("android") {
mavenPublication {
artifactId = "compat-android"
artifactId = "core-compat-android"
}
}
js {
browser()
}

targets.all {
val targetName = name
mavenPublication {
when (targetName) {
"android" -> artifactId = "core-android"
"jdk" -> artifactId = "core-jvm"
else -> {
artifactId = artifactId.replace("core", "compat")
}
}
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
if (this is HasConfigurableKotlinCompilerOptions<*>) {
compilerOptions {
Expand All @@ -86,19 +65,19 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(project(":core:base"))
api(projects.core)
}
}

val jdkMain by getting {
dependencies {
api(project(":core:jdk"))
api(projects.coreJdk)
}
}

val androidMain by getting {
dependencies {
api(project(":core:android"))
api(projects.coreAndroid)
}
}
}
Expand All @@ -109,7 +88,11 @@ addNativeTargets()
publishing {
publications.withType<MavenPublication>().named("kotlinMultiplatform") {
artifactId = "core"
components.named("kotlin") {
val c: ComponentWithVariants = this as ComponentWithVariants
logger.lifecycle("Found component \"kotlin\" with variants")
}
}
}

doPublish("core")
doPublish("compat")
File renamed without changes.
6 changes: 3 additions & 3 deletions core/jdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ kotlin {
}

dependencies {
api(project(":core:base"))
api(projects.core)

testImplementation(project(":testutil"))
testImplementation(project(":serialization"))
testImplementation(projects.testutil)
testImplementation(projects.serialization)
testImplementation(kotlin("test-junit5"))
testImplementation(libs.junit5.api)

Expand Down
4 changes: 2 additions & 2 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ base {
val autoModuleName = "net.devrieze.serialexamples"

dependencies {
implementation(project(":serialization"))
implementation(project(":serialutil"))
implementation(projects.serialization)
implementation(projects.serialutil)
}
18 changes: 9 additions & 9 deletions serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ kotlin {

val commonMain by getting {
dependencies {
api(project(":core:base"))
api(projects.core)

api(libs.serialization.core)
}
}

val commonTest by getting {
dependencies {
implementation(project(":serialutil"))
implementation(project(":testutil"))
implementation(projects.serialutil)
implementation(projects.testutil)
implementation(libs.serialization.json)

implementation(kotlin("test-common"))
Expand All @@ -141,12 +141,12 @@ kotlin {

val jvmMain by getting {
dependencies {
runtimeOnly(project(":core:jdk"))
runtimeOnly(projects.coreJdk)
}
}
val commonJvmTest by getting {
dependencies {
implementation(project(":core:jdk"))
implementation(projects.coreJdk)
}
}
val commonJvmMain by getting {}
Expand All @@ -165,8 +165,8 @@ kotlin {
val androidMain by getting {
dependencies {
compileOnly(libs.kxml2)
runtimeOnly(project(":core:android"))
api(project(":core:base")) {
runtimeOnly(projects.coreAndroid)
api(projects.core) {
attributes { attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) }
}
}
Expand All @@ -186,7 +186,7 @@ kotlin {

val jsMain by getting {
dependencies {
api(project(":core:base"))
api(projects.core)
}
}

Expand All @@ -201,7 +201,7 @@ kotlin {
all {
if (this.name == "nativeMain") {
dependencies {
api(project(":core:base"))
api(projects.core)
}
}
if (System.getProperty("idea.active") == "true" && name == "nativeTest") { // Hackery to get at the native source sets that shouldn't be needed
Expand Down
15 changes: 11 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,25 @@ plugins {
rootProject.name = "xmlutil"

include(":serialutil")
include(":core:compat")
include(":core:base")
include(":core:jdk")
include(":core:android")
include("coreCompat")
include("core")
include("coreJdk")
include("coreAndroid")

include(":serialization")
include(":xmlserializable")
include(":testutil")
include(":examples")

project(":core").projectDir = file("core/base")
project(":coreJdk").projectDir = file("core/jdk")
project(":coreAndroid").projectDir = file("core/android")
project(":coreCompat").projectDir = file("core/compat")

gradleEnterprise {
buildScan {
// plugin configuration
}
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
2 changes: 1 addition & 1 deletion testutil/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ kotlin {
dependencies {
api(libs.serialization.core)
api(kotlin("test"))
api(project(":core:base"))
api(projects.core)

}
}
Expand Down
2 changes: 1 addition & 1 deletion xmlserializable/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":core:base")) // Don't add a runtime dep here
implementation(projects.core) // Don't add a runtime dep here
implementation(libs.serialization.core)
}
}
Expand Down

0 comments on commit 8e82608

Please sign in to comment.