|
2 | 2 |
|
3 | 3 | package com.ensody.buildlogic |
4 | 4 |
|
| 5 | +import com.android.build.gradle.BaseExtension |
5 | 6 | import io.github.gradlenexus.publishplugin.NexusPublishExtension |
6 | 7 | import org.gradle.api.Plugin |
7 | 8 | import org.gradle.api.Project |
| 9 | +import org.gradle.api.artifacts.ProjectDependency |
| 10 | +import org.gradle.api.plugins.JavaPlatformExtension |
| 11 | +import org.gradle.api.publish.PublishingExtension |
8 | 12 | import org.gradle.kotlin.dsl.assign |
9 | 13 | import org.gradle.kotlin.dsl.configure |
10 | | -import org.gradle.kotlin.dsl.dependencies |
| 14 | +import org.gradle.kotlin.dsl.findByType |
11 | 15 | import org.gradle.kotlin.dsl.repositories |
| 16 | +import org.jetbrains.dokka.gradle.DokkaExtension |
| 17 | +import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension |
| 18 | +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension |
12 | 19 | import java.net.URI |
13 | 20 |
|
14 | 21 | class BuildLogicPlugin : Plugin<Project> { |
15 | | - override fun apply(target: Project) {} |
| 22 | + override fun apply(target: Project) { |
| 23 | + target.run { |
| 24 | + pluginManager.apply("com.ensody.build-logic-base") |
| 25 | + if (!isRootProject) { |
| 26 | + if (name.endsWith("-bom")) { |
| 27 | + pluginManager.apply("java-platform") |
| 28 | + } else { |
| 29 | + pluginManager.apply("com.android.library") |
| 30 | + pluginManager.apply("org.jetbrains.kotlin.multiplatform") |
| 31 | + if ("-compose" in name) { |
| 32 | + pluginManager.apply("org.jetbrains.compose") |
| 33 | + pluginManager.apply("org.jetbrains.kotlin.plugin.compose") |
| 34 | + } |
| 35 | + } |
| 36 | + pluginManager.apply("maven-publish") |
| 37 | + } |
| 38 | + pluginManager.apply("org.jetbrains.dokka") |
| 39 | + } |
| 40 | + } |
16 | 41 | } |
17 | 42 |
|
18 | 43 | fun Project.initBuildLogic() { |
19 | 44 | group = "com.ensody.reactivestate" |
20 | 45 |
|
21 | | - initBuildLogicBase() |
22 | | - allprojects { |
23 | | - setupBuildLogic() |
24 | | - } |
| 46 | + initBuildLogicBase { |
| 47 | + setupRepositories() |
25 | 48 |
|
26 | | - configure<NexusPublishExtension> { |
27 | | - repositories { |
28 | | - sonatype { |
29 | | - nexusUrl.set(URI("https://s01.oss.sonatype.org/service/local/")) |
30 | | - snapshotRepositoryUrl.set(URI("https://s01.oss.sonatype.org/content/repositories/snapshots/")) |
31 | | - username = System.getenv("PUBLICATION_USERNAME") |
32 | | - password = System.getenv("PUBLICATION_PASSWORD") |
| 49 | + configure<NexusPublishExtension> { |
| 50 | + repositories { |
| 51 | + sonatype { |
| 52 | + nexusUrl.set(URI("https://s01.oss.sonatype.org/service/local/")) |
| 53 | + snapshotRepositoryUrl.set(URI("https://s01.oss.sonatype.org/content/repositories/snapshots/")) |
| 54 | + username = System.getenv("PUBLICATION_USERNAME") |
| 55 | + password = System.getenv("PUBLICATION_PASSWORD") |
| 56 | + } |
33 | 57 | } |
34 | 58 | } |
35 | 59 | } |
36 | 60 | } |
37 | 61 |
|
38 | | -fun Project.setupBuildLogic() { |
39 | | - pluginManager.apply("com.ensody.build-logic") |
40 | | - |
| 62 | +fun Project.setupRepositories() { |
41 | 63 | repositories { |
42 | 64 | google() |
43 | 65 | mavenCentral() |
44 | 66 | if (System.getenv("RUNNING_ON_CI") != "true") { |
45 | 67 | mavenLocal() |
46 | 68 | } |
47 | 69 | } |
| 70 | +} |
48 | 71 |
|
49 | | - if (isRootProject) return |
50 | | - |
51 | | - setupBuildLogicBase() |
52 | | - |
53 | | - if (project.name.endsWith("-bom")) { |
54 | | - setupPlatformProject() |
55 | | - } else { |
56 | | - setupAndroid(coreLibraryDesugaring = libs.findLibrary("desugarJdkLibs").get()) |
57 | | - setupKmp { |
58 | | - addAllTargets(onlyComposeSupport = project.name == "reactivestate-compose") |
59 | | - compilerOptions { |
60 | | - optIn.add("kotlinx.coroutines.ExperimentalCoroutinesApi") |
61 | | - optIn.add("kotlinx.coroutines.ExperimentalForInheritanceCoroutinesApi") |
62 | | - optIn.add("kotlinx.coroutines.FlowPreview") |
63 | | - optIn.add("com.ensody.reactivestate.ExperimentalReactiveStateApi") |
64 | | - } |
65 | | - } |
66 | | - tasks.register("testAll") { |
67 | | - group = "verification" |
68 | | - dependsOn( |
69 | | - "testDebugUnitTest", |
70 | | - "jvmTest", |
71 | | - "iosSimulatorArm64Test", |
72 | | - "iosX64Test", |
73 | | - "macosArm64Test", |
74 | | - "macosX64Test", |
75 | | - "mingwX64Test", |
76 | | - "linuxX64Test", |
77 | | -// "linuxArm64Test", |
78 | | -// "tvosSimulatorArm64Test", |
79 | | -// "tvosX64Test", |
80 | | -// "watchosSimulatorArm64Test", |
81 | | -// "watchosX64Test", |
82 | | -// "jsIrNodeTest", |
83 | | - ) |
| 72 | +fun Project.setupBuildLogic(block: Project.() -> Unit) { |
| 73 | + setupBuildLogicBase { |
| 74 | + setupRepositories() |
| 75 | + if (extensions.findByType<JavaPlatformExtension>() != null) { |
| 76 | + setupPlatformProject() |
84 | 77 | } |
85 | | - |
86 | | - dependencies { |
87 | | - add("commonMainApi", platform(libs.findLibrary("coroutines-bom").get())) |
| 78 | + if (extensions.findByType<BaseExtension>() != null) { |
| 79 | + setupAndroid(coreLibraryDesugaring = libs.findLibrary("desugarJdkLibs").get()) |
88 | 80 | } |
89 | | - |
90 | | - setupKtLint(libs.findLibrary("ktlint-cli").get()) |
91 | | - setupDokka(copyright = "Ensody GmbH") |
92 | | - } |
93 | | - |
94 | | - setupPublication( |
95 | | - withJavadocJar = true, |
96 | | - withSources = true, |
97 | | - signingKeyInfo = SigningKeyInfo.loadFromEnvOrNull(), |
98 | | - ) { |
99 | | - pom { |
100 | | - name = "${rootProject.name}: ${project.name}" |
101 | | - description = "Kotlin Multiplatform ViewModels and reactive state management based on StateFlow" |
102 | | - url = "https://github.com/ensody/ReactiveState-Kotlin" |
103 | | - licenses { |
104 | | - apache2() |
| 81 | + if (extensions.findByType<KotlinMultiplatformExtension>() != null) { |
| 82 | + setupKmp { |
| 83 | + addAllTargets(onlyComposeSupport = project.name == "reactivestate-compose") |
| 84 | + compilerOptions { |
| 85 | + optIn.add("kotlinx.coroutines.ExperimentalCoroutinesApi") |
| 86 | + optIn.add("kotlinx.coroutines.ExperimentalForInheritanceCoroutinesApi") |
| 87 | + optIn.add("kotlinx.coroutines.FlowPreview") |
| 88 | + optIn.add("com.ensody.reactivestate.ExperimentalReactiveStateApi") |
| 89 | + } |
105 | 90 | } |
106 | | - scm { |
107 | | - url.set(this@pom.url) |
| 91 | + tasks.register("testAll") { |
| 92 | + group = "verification" |
| 93 | + dependsOn( |
| 94 | + "testDebugUnitTest", |
| 95 | + "jvmTest", |
| 96 | + "iosSimulatorArm64Test", |
| 97 | + "iosX64Test", |
| 98 | + "macosArm64Test", |
| 99 | + "macosX64Test", |
| 100 | + "mingwX64Test", |
| 101 | + "linuxX64Test", |
| 102 | +// "linuxArm64Test", |
| 103 | +// "tvosSimulatorArm64Test", |
| 104 | +// "tvosX64Test", |
| 105 | +// "watchosSimulatorArm64Test", |
| 106 | +// "watchosX64Test", |
| 107 | +// "jsIrNodeTest", |
| 108 | + ) |
108 | 109 | } |
109 | | - developers { |
110 | | - developer { |
111 | | - id = "wkornewald" |
112 | | - name = "Waldemar Kornewald" |
113 | | - url = "https://www.ensody.com" |
114 | | - organization = "Ensody GmbH" |
115 | | - organizationUrl = url |
| 110 | + } |
| 111 | + if (extensions.findByType<KotlinBaseExtension>() != null) { |
| 112 | + setupKtLint(libs.findLibrary("ktlint-cli").get()) |
| 113 | + } |
| 114 | + if (extensions.findByType<DokkaExtension>() != null) { |
| 115 | + setupDokka(copyright = "Ensody GmbH") |
| 116 | + } |
| 117 | + if (extensions.findByType<PublishingExtension>() != null) { |
| 118 | + setupPublication( |
| 119 | + withJavadocJar = true, |
| 120 | + withSources = true, |
| 121 | + signingKeyInfo = SigningKeyInfo.loadFromEnvOrNull(), |
| 122 | + ) { |
| 123 | + pom { |
| 124 | + name = "${rootProject.name}: ${project.name}" |
| 125 | + description = "Kotlin Multiplatform ViewModels and reactive state management based on StateFlow" |
| 126 | + url = "https://github.com/ensody/ReactiveState-Kotlin" |
| 127 | + licenses { |
| 128 | + apache2() |
| 129 | + } |
| 130 | + scm { |
| 131 | + url.set(this@pom.url) |
| 132 | + } |
| 133 | + developers { |
| 134 | + developer { |
| 135 | + id = "wkornewald" |
| 136 | + name = "Waldemar Kornewald" |
| 137 | + url = "https://www.ensody.com" |
| 138 | + organization = "Ensody GmbH" |
| 139 | + organizationUrl = url |
| 140 | + } |
| 141 | + } |
116 | 142 | } |
117 | 143 | } |
118 | 144 | } |
| 145 | + block() |
119 | 146 | } |
120 | 147 | } |
0 commit comments