Skip to content

Commit 168d87e

Browse files
committed
moved libraries.json to be auto-generated on publishing :core only.
1 parent 533ac2e commit 168d87e

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

core/build.gradle.kts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import com.google.devtools.ksp.gradle.KspTaskJvm
33
import io.github.devcrocod.korro.KorroTask
44
import nl.jolanrensen.kodex.gradle.creatingRunKodexTask
55
import org.gradle.jvm.tasks.Jar
6-
import org.gradle.kotlin.dsl.withType
6+
import org.intellij.lang.annotations.Language
77
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
88

99
plugins {
@@ -251,15 +251,71 @@ val changeJarTask by tasks.registering {
251251
}
252252
}
253253

254+
// generateLibrariesJson makes sure a META-INF/kotlin-jupyter-libraries/libraries.json file is generated
255+
// This file allows loading dataframe-jupyter when dataframe-core is present on its own in a Kotlin Notebook.
256+
val generatedJupyterResourcesDir = layout.buildDirectory.dir("generated/jupyter")
257+
val generateLibrariesJson by tasks.registering {
258+
val outDir = generatedJupyterResourcesDir.get().asFile.resolve("META-INF/kotlin-jupyter-libraries")
259+
val outFile = outDir.resolve("libraries.json")
260+
outputs.file(outFile)
261+
262+
doLast {
263+
outDir.mkdirs()
264+
@Language("json")
265+
val content =
266+
"""
267+
{
268+
"descriptors": [
269+
{
270+
"init": [
271+
"USE { dependencies(\"org.jetbrains.kotlinx:dataframe-jupyter:${project.version}\") }"
272+
]
273+
}
274+
]
275+
}
276+
""".trimIndent()
277+
278+
outFile.delete()
279+
outFile.writeText(content)
280+
logger.lifecycle("generated META-INF/kotlin-jupyter-libraries/libraries.json for :core")
281+
}
282+
}
283+
284+
// If `changeProcessResourcesTask` is run, modify the processResources task such that before running,
285+
// a META-INF libraries.json file is added to the resources.
286+
// This file allows loading dataframe-jupyter when dataframe-core is present on its own in a Kotlin Notebook.
287+
// This is usually only done when publishing.
288+
val changeProcessResourcesTask by tasks.registering {
289+
doFirst {
290+
tasks.processResources {
291+
from(generatedJupyterResourcesDir) {
292+
into("") // keep META-INF/... structure as generated
293+
}
294+
doLast {
295+
logger.lifecycle("$this includes generated META-INF/kotlin-jupyter-libraries/libraries.json")
296+
}
297+
}
298+
}
299+
}
300+
tasks.processResources {
301+
mustRunAfter(changeProcessResourcesTask)
302+
dependsOn(generateLibrariesJson)
303+
}
304+
254305
// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
255306
tasks.withType<Jar> {
256307
mustRunAfter(changeJarTask, tasks.generateKeywordsSrc, processKDocsMain)
257308
}
258309

259310
// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
311+
// also `changeProcessResourcesTask`, so libraries.json is included in the resources
260312
tasks.configureEach {
261-
if (!project.hasProperty("skipKodex") && name.startsWith("publish")) {
262-
dependsOn(processKDocsMain, changeJarTask)
313+
if (name.startsWith("publish")) {
314+
dependsOn(changeProcessResourcesTask)
315+
316+
if (!project.hasProperty("skipKodex")) {
317+
dependsOn(processKDocsMain, changeJarTask)
318+
}
263319
}
264320
}
265321

core/src/main/resources/META-INF/kotlin-jupyter-libraries/libraries.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)