Skip to content

Commit

Permalink
fix(buildSrc): improve LibraryType convention config
Browse files Browse the repository at this point in the history
Additionally, set some default conventions for Kotlin/JVM modules
  • Loading branch information
EdricChan03 committed May 6, 2024
1 parent 142c688 commit 4d8378b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.SigningExtension
import org.gradle.plugins.signing.SigningPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import java.net.URI
import com.android.build.gradle.LibraryExtension as AGPLibraryExtension
import com.android.build.gradle.LibraryPlugin as AGPLibraryPlugin
Expand Down Expand Up @@ -237,13 +238,25 @@ class LibraryPlugin : Plugin<Project> {
}

private fun Property<LibraryType>.setConventions(project: Project) {
with(project.plugins) {
with(project) {
convention(
when {
hasPlugin(AGPLibraryPlugin::class) -> LibraryType.Android
hasPlugin(KotlinMultiplatformPluginWrapper::class) -> LibraryType.Multiplatform
hasPlugin(KotlinPlatformJvmPlugin::class) -> LibraryType.Jvm
else -> null
plugins.hasPlugin(AGPLibraryPlugin::class) ||
extensions.hasType<AGPLibraryExtension>() -> LibraryType.Android

plugins.hasPlugin(KotlinMultiplatformPluginWrapper::class) ||
extensions.hasType<KotlinMultiplatformExtension>() -> LibraryType.Multiplatform

plugins.hasPlugin(KotlinPluginWrapper::class) ||
extensions.hasType<KotlinJvmProjectExtension>() -> LibraryType.Jvm

else -> {
logger.warn(
"No supported plugin for ${project.name} was found, " +
"assuming JVM project as the library type"
)
LibraryType.Jvm
}
}
)
}
Expand Down Expand Up @@ -351,6 +364,10 @@ class LibraryPlugin : Plugin<Project> {
setConventions()
configureKmpPublications(project)
}
// Kotlin/JVM
extensions.findByType<KotlinJvmProjectExtension>()?.apply {
setConventions()
}

// Dokkatoo
extensions.findByType<DokkatooExtension>()?.setConventions(project, extension.docs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.edricchan03.plugin.library.extensions

enum class LibraryType {
/** Denotes a pure Kotlin/JVM project. */
/** Denotes a pure Kotlin/JVM project. This is the default value if not specified. */
Jvm,

/** Denotes an Android project. */
Expand Down

0 comments on commit 4d8378b

Please sign in to comment.