@@ -3,7 +3,7 @@ import com.google.devtools.ksp.gradle.KspTaskJvm
3
3
import io.github.devcrocod.korro.KorroTask
4
4
import nl.jolanrensen.kodex.gradle.creatingRunKodexTask
5
5
import org.gradle.jvm.tasks.Jar
6
- import org.gradle.kotlin.dsl.withType
6
+ import org.intellij.lang.annotations.Language
7
7
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
8
8
9
9
plugins {
@@ -251,15 +251,71 @@ val changeJarTask by tasks.registering {
251
251
}
252
252
}
253
253
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
+
254
305
// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
255
306
tasks.withType<Jar > {
256
307
mustRunAfter(changeJarTask, tasks.generateKeywordsSrc, processKDocsMain)
257
308
}
258
309
259
310
// 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
260
312
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
+ }
263
319
}
264
320
}
265
321
0 commit comments