Skip to content

Commit

Permalink
Rename the modules instead of hacking the artifactId value
Browse files Browse the repository at this point in the history
This should make issues like #280 impossible.
  • Loading branch information
LouisCAD committed Jul 30, 2021
1 parent 6d8b1e6 commit 48ec240
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2019-2021 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("PackageDirectoryMismatch")
Expand All @@ -8,5 +8,8 @@ import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.project
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler

fun DependencyHandler.splitties(splitName: String) = project(":modules:$splitName")
fun KotlinDependencyHandler.splitties(splitName: String) = project(":modules:$splitName")
fun DependencyHandler.splitties(splitName: String) = project(":modules:splitties-$splitName")
fun KotlinDependencyHandler.splitties(splitName: String) = project(":modules:splitties-$splitName")

fun DependencyHandler.splittiesFunPack(funPackName: String) = project(":fun-packs:splitties-fun-pack-$funPackName")
fun KotlinDependencyHandler.splittiesFunPack(funPackName: String) = project(":fun-packs:splitties-fun-pack-$funPackName")
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@

@file:Suppress("PackageDirectoryMismatch")

import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.androidJvm
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.common
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.js
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.native
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import java.util.Locale

fun KotlinTarget.configureMavenPublication(
publishReleaseVariantOnly: Boolean = false
Expand All @@ -23,18 +17,7 @@ fun KotlinTarget.configureMavenPublication(
}
val isInMultiplatformModule = project.plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")
if (isInMultiplatformModule.not()) return // The mavenPublication block would not be run anyway.
val suffix = when (platformType) {
common -> "-metadata"
jvm -> "-jvm"
js -> "-js"
androidJvm -> "-android"
native -> "-${name.toLowerCase(Locale.ROOT)}"
}
mavenPublication {
val prefix = if (project.isFunPack) "splitties-fun-pack" else "splitties"
project.afterEvaluate {
artifactId = "$prefix-${project.name}$suffix"
}
if (publishReleaseVariantOnly && platformType == androidJvm) {
// We disable metadata generation for Android publications, so the release variants can
// be used for any buildType of the consumer projects without having to specify
Expand All @@ -56,5 +39,3 @@ fun KotlinTarget.configureMavenPublication(
}
}
}

val Project.isFunPack: Boolean get() = parent?.name == "fun-packs"
6 changes: 0 additions & 6 deletions buildSrc/src/main/kotlin/publishing/publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ publishing {
artifact(project.tasks.emptyJavadocJar())
setupPom()
}
mavenPublications.findByName("kotlinMultiplatform")?.let {
val prefix = if (project.isFunPack) "splitties-fun-pack" else "splitties"
project.afterEvaluate {
it.artifactId = "$prefix-${project.name}"
}
}
repositories {
mavenCentralStaging(
project = project,
Expand Down
4 changes: 2 additions & 2 deletions fun-packs/android-appcompat-with-views-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ kotlin {
configure(targets) { configureMavenPublication() }
sourceSets {
androidMain.dependencies {
api(project(":fun-packs:android-appcompat"))
api(project(":fun-packs:android-base-with-views-dsl"))
api(splittiesFunPack("android-appcompat"))
api(splittiesFunPack("android-base-with-views-dsl"))
api(splitties("views-dsl-appcompat"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion fun-packs/android-appcompat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ kotlin {
configure(targets) { configureMavenPublication() }
sourceSets {
androidMain.dependencies {
api(project(":fun-packs:android-base"))
api(splittiesFunPack("android-base"))
listOf(
"alertdialog-appcompat",
"alertdialog-appcompat-coroutines",
Expand Down
2 changes: 1 addition & 1 deletion fun-packs/android-base-with-views-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ kotlin {
configure(targets) { configureMavenPublication() }
sourceSets {
androidMain.dependencies {
api(project(":fun-packs:android-base"))
api(splittiesFunPack("android-base"))
listOf(
"views-dsl",
"views-dsl-constraintlayout",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ kotlin {
configure(targets) { configureMavenPublication() }
sourceSets {
androidMain.dependencies {
api(project(":fun-packs:android-material-components"))
api(project(":fun-packs:android-appcompat-with-views-dsl"))
api(splittiesFunPack("android-material-components"))
api(splittiesFunPack("android-appcompat-with-views-dsl"))
listOf(
"views-dsl-coordinatorlayout",
"views-dsl-material"
Expand Down
2 changes: 1 addition & 1 deletion fun-packs/android-material-components/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ kotlin {
configure(targets) { configureMavenPublication() }
sourceSets {
androidMain.dependencies {
api(project(":fun-packs:android-appcompat"))
api(splittiesFunPack("android-appcompat"))
listOf(
"alertdialog-material",
"material-lists",
Expand Down
2 changes: 1 addition & 1 deletion samples/android-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ kotlin {
api(Kotlin.stdlib.common)
}
androidMain.dependencies {
implementation(project(":fun-packs:android-material-components-with-views-dsl"))
implementation(splittiesFunPack("android-material-components-with-views-dsl"))
arrayOf(
"arch-lifecycle",
"arch-room",
Expand Down
28 changes: 21 additions & 7 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ include {
"samples" {
"android-app"()
}
"fun-packs" {
"fun-packs"(childrenPrefix = "splitties-fun-pack-") {
"android-base"()
"android-base-with-views-dsl"()
"android-appcompat"()
Expand All @@ -47,7 +47,7 @@ include {

if (checkPublication) "tools" { "publication-checker"() }

"modules" {
"modules"(childrenPrefix = "splitties-") {
"activities"()
"alertdialog"()
"alertdialog-appcompat"()
Expand Down Expand Up @@ -104,18 +104,32 @@ include {
//region include DSL
class ModuleParentScope(
private val name: String,
private val parent: ModuleParentScope? = null
private val parent: ModuleParentScope? = null,
private val prefix: String
) {

operator fun String.invoke(block: (ModuleParentScope.() -> Unit)? = null) {
operator fun String.invoke(
childrenPrefix: String = "",
block: (ModuleParentScope.() -> Unit)? = null
) {
check(startsWith(':').not())
val moduleName = ":$this"
val projectName = "$parentalPath$moduleName"
include(projectName)
project(projectName).let {
println("Project [before]: ${it.name}, ${it.path}, $projectName")
}
if (prefix.isNotEmpty()) {
project(projectName).let {
it.name = "$prefix${it.name}"
println("Project [after]: ${it.name}, ${it.path}, $projectName")
}
}
block?.let { buildNode ->
ModuleParentScope(
name = moduleName,
parent = this@ModuleParentScope
parent = this@ModuleParentScope,
prefix = childrenPrefix
).buildNode()
}
}
Expand All @@ -126,7 +140,7 @@ class ModuleParentScope(

}

inline fun include(block: ModuleParentScope.() -> Unit) {
ModuleParentScope("").block()
inline fun include(prefix: String = "", block: ModuleParentScope.() -> Unit) {
ModuleParentScope(name = "", prefix = prefix).block()
}
//endregion

0 comments on commit 48ec240

Please sign in to comment.