Skip to content

Commit 5d1f0de

Browse files
committed
chore: fix publish task, dokka and dep updates
1 parent 577bbd4 commit 5d1f0de

File tree

12 files changed

+184
-102
lines changed

12 files changed

+184
-102
lines changed

benchmark/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
plugins { plugins.kotlin.benchmark }
22

3-
// mppTargetName = "jvm"
43
dependencies { commonMainImplementation(projects.common) }
File renamed without changes.

gradle/build-logic/common-plugins/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ dependencies {
128128
implementation(libs.build.kotlinx.kover)
129129
implementation(libs.build.kotlinx.benchmark)
130130
implementation(libs.build.kotlinx.bincompat)
131-
implementation(libs.build.dokka)
132-
implementation(libs.build.ksp.redacted)
131+
implementation(libs.build.dokka.plugin)
132+
implementation(libs.build.dokka.base)
133+
implementation(libs.build.redacted.plugin)
133134
implementation(libs.build.gradle.enterprise)
134135
implementation(libs.build.nexus.plugin)
135136
implementation(libs.build.spotless.plugin)

gradle/build-logic/common-plugins/src/main/kotlin/common/CommonExtns.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import java.nio.file.Files
66
import java.nio.file.Path
77
import java.text.DecimalFormat
88
import java.text.NumberFormat
9+
import kotlin.jvm.optionals.getOrNull
910
import kotlin.math.ln
1011
import kotlin.math.pow
1112
import kotlin.properties.ReadOnlyProperty
@@ -19,6 +20,35 @@ internal val DEC_FORMAT = DecimalFormat("#.##")
1920
/** OS temp location */
2021
val tmp: String = "${System.getProperty("java.io.tmpdir")}${File.separator}"
2122

23+
/** Returns the method name contains this call-site */
24+
inline val methodName
25+
get() = StackWalker.getInstance().walk { it.findFirst().getOrNull()?.methodName }
26+
27+
/** Read the [Class] as [ByteArray] */
28+
fun <T : Class<*>> T.toBytes() =
29+
classLoader.getResourceAsStream("${name.replace('.', '/')}.class")?.readBytes()
30+
31+
/**
32+
* Returns the actual class URL
33+
*
34+
* ```
35+
* val url = LogManager::class.java.resourcePath
36+
* ```
37+
*/
38+
val <T : Class<*>> T.resourcePath
39+
get() = getResource("$simpleName.class")
40+
41+
/** Run the lambda in the context of the receiver classloader. */
42+
fun ClassLoader.using(run: () -> Unit) {
43+
val cl = Thread.currentThread().contextClassLoader
44+
try {
45+
Thread.currentThread().contextClassLoader = this
46+
run()
47+
} finally {
48+
Thread.currentThread().contextClassLoader = cl
49+
}
50+
}
51+
2252
/** Returns the file size in a human-readable format. */
2353
val File.displaySize
2454
get() = length().byteDisplaySize()
@@ -55,6 +85,15 @@ fun Long.byteDisplaySize(si: Boolean = true): String {
5585
}
5686
}
5787

88+
fun IntArray.codePointsToString(): String = buildString {
89+
for (cp in this@codePointsToString) {
90+
appendCodePoint(cp)
91+
}
92+
}
93+
94+
fun IntArray.codePointsToString(separator: String = "") =
95+
joinToString(separator) { Character.toString(it) }
96+
5897
/** Find the file ends with given [format] under the directory. */
5998
fun File.findPkg(format: String?) =
6099
when (format != null) {

gradle/build-logic/common-plugins/src/main/kotlin/common/ProjectExtns.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream
44
import java.io.File
55
import java.nio.file.Path
66
import org.gradle.accessors.dm.LibrariesForLibs
7+
import org.gradle.api.Action
78
import org.gradle.api.JavaVersion
89
import org.gradle.api.Project
910
import org.gradle.api.Task
@@ -131,6 +132,7 @@ fun Project.jvmArguments(forAppRun: Boolean = false) = buildList {
131132
"-XX:+UseZGC",
132133
"-XX:+ZGenerational",
133134
"-XX:+UseCompressedOops",
135+
"-XX:+UseStringDeduplication",
134136
"-XX:+UnlockExperimentalVMOptions",
135137
// os+thread,gc+heap=trace,
136138
"""-Xlog:cds,safepoint,gc*:
@@ -189,6 +191,7 @@ fun Project.jvmArguments(forAppRun: Boolean = false) = buildList {
189191
// "-XshowSettings:system",
190192
// "-XshowSettings:properties",
191193
// "--show-module-resolution",
194+
// "-XX:+UseCompactObjectHeaders",
192195
// "-XX:+ShowHiddenFrames",
193196
// "-XX:+AutoCreateSharedArchive",
194197
// "-XX:SharedArchiveFile=$tmp/$name.jsa"
@@ -613,10 +616,15 @@ fun Project.addFileToJavaComponent(file: File) {
613616

614617
/** Lazy version of [TaskContainer.maybeCreate] */
615618
inline fun <reified T : Task> TaskContainer.maybeRegister(
616-
taskName: String,
617-
noinline configAction: T.() -> Unit
619+
name: String,
620+
action: Action<in T>? = null,
618621
) =
619-
when (taskName) {
620-
in names -> named(taskName, T::class)
621-
else -> register(taskName, T::class)
622-
}.also { it.configure(configAction) }
622+
when (name) {
623+
// val taskCollection = withType<T>().matching { it.name == name }
624+
in names -> named<T>(name = name)
625+
else -> register<T>(name = name)
626+
}.also {
627+
if (action != null) {
628+
it.configure(action)
629+
}
630+
}

gradle/build-logic/common-plugins/src/main/kotlin/plugins/common.gradle.kts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package plugins
22

3-
import com.github.ajalt.mordant.rendering.TextColors
3+
import com.github.ajalt.mordant.rendering.TextColors.*
44
import common.*
55
import common.Platform
66
import java.io.PrintWriter
77
import java.io.StringWriter
88
import java.util.spi.*
9+
import org.gradle.api.publish.plugins.PublishingPlugin.*
910
import org.gradle.internal.os.OperatingSystem
1011
import org.gradle.kotlin.dsl.*
1112
import tasks.*
@@ -20,7 +21,7 @@ plugins {
2021

2122
if (hasCleanTask) {
2223
logger.warn(
23-
TextColors.yellow(
24+
yellow(
2425
"""
2526
| CLEANING ALMOST NEVER FIXES YOUR BUILD!
2627
| Cleaning is often a last-ditch effort to fix perceived build problems that aren't going to
@@ -32,7 +33,9 @@ if (hasCleanTask) {
3233
)
3334
}
3435

35-
afterEvaluate { logger.lifecycle(TextColors.magenta("=== Project Configuration Completed ===")) }
36+
afterEvaluate {}
37+
38+
gradle.projectsEvaluated { logger.lifecycle(magenta("=== Projects Configuration Completed ===")) }
3639

3740
idea {
3841
module {
@@ -150,17 +153,36 @@ tasks {
150153
}
151154
}
152155

156+
// Auto format all source files
157+
processResources { dependsOn(":spotlessApply") }
158+
153159
// Set GitHub workflow action output for this build
154160
build { finalizedBy(githubActionOutput) }
155161

156162
val buildAndPublish by registering {
157163
dependsOn(subprojects.map { it.tasks.build })
164+
// Starting with column(:) means root project tasks
158165
dependsOn(":dokkaHtmlMultiModule", ":koverHtmlReport")
159166

160-
val publish = GithubAction.isTagBuild && Platform.isLinux
161-
if (publish) {
162-
logger.lifecycle("Publishing task is enabled for this build!")
163-
subprojects.mapNotNull { it.tasks.findByName(":publish") }.forEach { dependsOn(it) }
167+
when {
168+
// Publishing to all repos on GitHub Action tag build
169+
GithubAction.isTagBuild && Platform.isLinux -> {
170+
logger.lifecycle(magenta("Publishing to all repositories is enabled!"))
171+
allprojects
172+
.mapNotNull { it.tasks.findByName(PUBLISH_LIFECYCLE_TASK_NAME) }
173+
.forEach { dependsOn(it) }
174+
}
175+
176+
// Publish is disabled on GitHub Action PR build
177+
GithubAction.isEnabled -> logger.lifecycle(red("Publishing is disabled!"))
178+
179+
// Publishing to local repo on other platforms
180+
else -> {
181+
logger.lifecycle(yellow("Publishing to local repo is enabled!"))
182+
allprojects
183+
.mapNotNull { it.tasks.findByName("publishAllPublicationsToMavenLocal") }
184+
.forEach { dependsOn(it) }
185+
}
164186
}
165187
}
166188

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package plugins
22

3-
import common.githubRepo
4-
import common.githubUser
5-
import common.kotlinJvmTarget
3+
import common.*
64
import java.net.URI
75
import kotlinx.validation.ApiValidationExtension
86
import org.gradle.kotlin.dsl.*
97
import org.hildan.github.changelog.plugin.GitHubChangelogExtension
108
import org.jetbrains.dokka.DokkaConfiguration.Visibility
9+
import org.jetbrains.dokka.base.DokkaBase
10+
import org.jetbrains.dokka.base.DokkaBaseConfiguration
1111
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
1212
import org.jetbrains.dokka.gradle.DokkaTaskPartial
1313

@@ -22,8 +22,13 @@ if (project == rootProject) {
2222
apply(plugin = "org.hildan.github.changelog")
2323
apply(plugin = "org.jetbrains.kotlinx.binary-compatibility-validator")
2424

25-
// For combined Kotlin coverage report
26-
dependencies { project.subprojects.forEach { kover(it) } }
25+
// Combined test & coverage report
26+
dependencies {
27+
project.subprojects.forEach {
28+
kover(it)
29+
// testReportAggregation(it)
30+
}
31+
}
2732

2833
// Dokka multi-module config.
2934
tasks.withType<DokkaMultiModuleTask>().configureEach {
@@ -43,47 +48,41 @@ plugins.withId("org.hildan.github.changelog") {
4348

4449
tasks {
4550
withType<DokkaTaskPartial>().configureEach {
46-
dokkaSourceSets.configureEach {
47-
moduleName = project.name
48-
jdkVersion = kotlinJvmTarget.map { it.target.toInt() }
49-
noStdlibLink = false
50-
noJdkLink = false
51-
reportUndocumented = false
52-
skipDeprecated = true
53-
// includes.from("README.md")
51+
dokkaSourceSets {
52+
// register("customSourceSet") {}
53+
configureEach {
54+
moduleName = project.name
55+
jdkVersion = kotlinJvmTarget.map { it.target.toInt() }
56+
noStdlibLink = false
57+
noJdkLink = false
58+
reportUndocumented = false
59+
skipDeprecated = true
60+
// includes.from("README.md")
61+
documentedVisibilities = setOf(Visibility.PUBLIC, Visibility.PROTECTED)
5462

55-
documentedVisibilities = setOf(Visibility.PUBLIC, Visibility.PROTECTED)
63+
sourceLink {
64+
localDirectory = rootProject.projectDir
65+
remoteUrl = URI("${githubRepo}/tree/main").toURL()
66+
remoteLineSuffix = "#L"
67+
}
5668

57-
sourceLink {
58-
localDirectory = rootProject.projectDir
59-
remoteUrl = URI("${githubRepo}/tree/main").toURL()
60-
remoteLineSuffix = "#L"
69+
// externalDocumentationLink(url = "https://kotlinlang.org/api/kotlinx.coroutines/")
70+
// externalDocumentationLink(url = "https://kotlinlang.org/api/kotlinx.serialization/")
71+
// externalDocumentationLink(url = "https://kotlinlang.org/api/kotlinx-datetime/",
72+
// packageListUrl =
73+
// "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list")
74+
// externalDocumentationLink(url = "https://api.ktor.io/")
6175
}
62-
63-
// externalDocumentationLink(url = "https://kotlinlang.org/api/kotlinx.coroutines/")
64-
// externalDocumentationLink(url = "https://kotlinlang.org/api/kotlinx.serialization/")
65-
// externalDocumentationLink(
66-
// url = "https://kotlinlang.org/api/kotlinx-datetime/",
67-
// packageListUrl =
68-
// "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list",
69-
// )
70-
// externalDocumentationLink(url = "https://api.ktor.io/")
7176
}
7277

73-
pluginsMapConfiguration =
74-
mapOf(
75-
"org.jetbrains.dokka.base.DokkaBase" to
76-
"""{ "footerMessage": "Copyright &copy; 2023 Dokka"}""")
77-
78-
// val rootPath = rootProject.rootDir.toPath()
79-
// val logoCss = rootPath.resolve("docs/css/logo-styles.css").toString().replace('\\', '/')
80-
// val paletteSvg = rootPath.resolve("docs/img/img.svg").toString().replace('\\', '/')
81-
// pluginsMapConfiguration = mapOf(
82-
// "org.jetbrains.dokka.base.DokkaBase" to """{
83-
// "customStyleSheets": ["$logoCss"],
84-
// "customAssets": ["$paletteSvg"],
85-
// "footerMessage": "Copyright &copy; 2021 AJ Alt"
86-
// }"""
87-
// )
78+
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
79+
// Dokka's stylesheets and assets with conflicting names will be overridden.
80+
// val rootPath = rootProject.rootDir.toPath()
81+
// val logoCss = rootPath.resolve("docs/css/logo-styles.css").toString()
82+
// val logSvg = rootPath.resolve("docs/img/app-logo.svg").toString()
83+
customStyleSheets = listOf(file("logo-styles.css"))
84+
customAssets = listOf(file("app-logo.svg"))
85+
footerMessage = "Copyright &copy; 2023 suresh.dev"
86+
}
8887
}
8988
}

gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.jvm.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ ksp {
6262
arg("autoserviceKsp.verbose", "true")
6363
}
6464

65-
redacted { enabled = true }
65+
redacted {
66+
enabled = true
67+
replacementString = ""
68+
}
6669

6770
kover {
6871
// useJacoco()
@@ -142,9 +145,11 @@ dependencies {
142145
implementation(libs.kotlinx.serialization.json)
143146
implementation(libs.kotlinx.datetime)
144147
implementation(libs.kotlinx.atomicfu)
148+
implementation(libs.kotlin.redacted.annotations)
145149
// Auto-service
146150
ksp(libs.ksp.auto.service)
147151
implementation(libs.google.auto.annotations)
152+
148153
// Test dependencies
149154
testImplementation(platform(libs.junit.bom))
150155
testImplementation(kotlin("test-junit5"))

gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.mpp.gradle.kts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import common.*
55
import org.jetbrains.kotlin.gradle.dsl.*
66
import org.jetbrains.kotlin.gradle.dsl.jvm.JvmTargetValidationMode
77
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
8+
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
89
import org.jetbrains.kotlin.gradle.targets.js.nodejs.*
910
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
1011
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
@@ -98,7 +99,6 @@ kotlinMultiplatform.apply {
9899

99100
// Disable wasm by default as some of the common dependencies are not compatible with wasm.
100101
if (project.hasProperty("experimental")) {
101-
102102
wasm {
103103
binaries.executable()
104104
browser {
@@ -139,6 +139,7 @@ kotlinMultiplatform.apply {
139139
api(libs.kotlinx.atomicfu)
140140
api(libs.kotlinx.serialization.json)
141141
api(libs.kotlinx.collections.immutable)
142+
api(libs.kotlin.redacted.annotations)
142143
}
143144
}
144145

@@ -188,6 +189,7 @@ kotlinMultiplatform.apply {
188189
// kotlin.srcDir("src/main/kotlin")
189190
// resources.srcDir("src/main/resources")
190191
}
192+
191193
val jsTest by getting
192194
}
193195

@@ -206,7 +208,10 @@ atomicfu {
206208
jvmVariant = "VH"
207209
}
208210

209-
redacted { enabled = true }
211+
redacted {
212+
enabled = true
213+
replacementString = ""
214+
}
210215

211216
kover {
212217
// useJacoco()
@@ -228,11 +233,13 @@ val commonJsResources by
228233
}
229234

230235
tasks {
236+
// Register buildConfig task only for common module
231237
if (project.name == commonProjectName) {
232-
// Register buildConfig task only for common module
233238
val buildConfigExtn = extensions.create<BuildConfigExtension>("buildConfig")
234239
val buildConfig by register<BuildConfig>("buildConfig", buildConfigExtn)
235-
kotlinMultiplatform.sourceSets.named("${commonProjectName}Main") { kotlin.srcDirs(buildConfig) }
240+
kotlinMultiplatform.sourceSets.named(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) {
241+
kotlin.srcDirs(buildConfig)
242+
}
236243
// maybeRegister<Task>("prepareKotlinIdeaImport") { dependsOn(buildConfig) }
237244
}
238245

0 commit comments

Comments
 (0)