Skip to content

Commit f39e3c8

Browse files
committed
Add publishing to plugin portal
1 parent d1ed147 commit f39e3c8

File tree

12 files changed

+127
-71
lines changed

12 files changed

+127
-71
lines changed

build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ tasks.register("publishLocal") {
119119
)
120120
}
121121

122+
tasks.register("publishToPluginPortal") {
123+
group = "publishing"
124+
125+
dependsOn(
126+
":api-gradle-plugin:publishPlugins"
127+
)
128+
}
129+
122130
tasks.jar {
123131
manifest {
124132
attributes["Main-Class"] = taskOptions.mainClassFQN

docs/libraries.md

+8-57
Original file line numberDiff line numberDiff line change
@@ -52,68 +52,27 @@ You may also add a Kotlin kernel integration to your library using a
5252
In the following code snippets `<jupyterApiVersion>` is one of the published versions from the link above.
5353
It is encouraged to use the latest stable version.
5454

55-
First, adjust your `settings.gradle` file:
56-
```groovy
57-
pluginManagement {
58-
repositories {
59-
maven("https://kotlin.bintray.com/kotlin-datascience/")
60-
}
61-
62-
resolutionStrategy {
63-
eachPlugin {
64-
if (requested.id.id == 'org.jetbrains.kotlinx.jupyter.api.plugin') {
65-
useModule('org.jetbrains.kotlinx.jupyter:kotlin-jupyter-api-gradle-plugin:<jupyterApiVersion>')
66-
}
67-
}
68-
}
69-
}
70-
```
71-
72-
Or, **alternatively**, your `setting.gradle.kts` file:
73-
```kotlin
74-
pluginManagement {
75-
repositories {
76-
maven("https://kotlin.bintray.com/kotlin-datascience/")
77-
}
78-
79-
resolutionStrategy {
80-
eachPlugin {
81-
when (requested.id.id) {
82-
"org.jetbrains.kotlinx.jupyter.api.plugin" -> useModule("org.jetbrains.kotlinx.jupyter:kotlin-jupyter-api-gradle-plugin:<jupyterApiVersion>")
83-
}
84-
}
85-
}
86-
}
87-
```
88-
89-
Then, add the plugin and API dependencies into your buildscript.
55+
First, add the plugin dependency into your buildscript.
9056

9157
For `build.gradle`:
9258
```groovy
9359
plugins {
94-
id "org.jetbrains.kotlinx.jupyter.api.plugin" version "<jupyterApiVersion>"
95-
}
96-
97-
dependencies {
98-
implementation "org.jetbrains.kotlin:kotlin-stdlib"
99-
implementation "org.jetbrains.kotlin:kotlin-reflect"
100-
compileOnly("org.jetbrains.kotlinx.jupyter:kotlin-jupyter-api:<jupyterApiVersion>")
60+
id "org.jetbrains.kotlin.jupyter.api" version "<jupyterApiVersion>"
10161
}
10262
```
10363

10464
For `build.gradle.kts`:
10565
```kotlin
10666
plugins {
107-
id("org.jetbrains.kotlinx.jupyter.api.plugin") version "<jupyterApiVersion>"
108-
}
109-
110-
dependencies {
111-
implementation(kotlin("stdlib"))
112-
implementation(kotlin("reflect"))
113-
compileOnly("org.jetbrains.kotlinx.jupyter:kotlin-jupyter-api:<jupyterApiVersion>")
67+
kotlin("jupyter.api") version "<jupyterApiVersion>"
11468
}
11569
```
11670

71+
This plugin adds dependencies to api and annotations ("scanner") artifacts to your project. You may turn of
72+
the auto-including of these artifacts by specifying following Gradle properties:
73+
- `kotlin.jupyter.add.api` to `false`. Add it manually using `org.jetbrains.kotlinx.jupyter.api.plugin.UtilKt.addKotlinJupyterApiDependency`
74+
- `kotlin.jupyter.add.scanner` to `false`. Add it manually using `org.jetbrains.kotlinx.jupyter.api.plugin.UtilKt.addKotlinJupyterScannerDependency`
75+
11776
Finally, refer your implementations of `org.jetbrains.kotlinx.jupyter.api.libraries.LibraryDefinitionProducer` and/or
11877
`org.jetbrains.kotlinx.jupyter.api.libraries.LibraryDefinition` in your buildscript.
11978

@@ -162,14 +121,6 @@ definitions inside your JAR - you may mark them with special annotations
162121
and attach specific annotation processor to process them. See how it
163122
works.
164123

165-
Add these two additional dependencies to your buildscript:
166-
```groovy
167-
dependencies {
168-
implementation("org.jetbrains.kotlinx.jupyter:kotlin-jupyter-api-annotations:<jupyterApiVersion>")
169-
kapt("org.jetbrains.kotlinx.jupyter:kotlin-jupyter-api-annotations:<jupyterApiVersion>")
170-
}
171-
```
172-
173124
Now you don't need to specify options for `processJupyterApiResources` task.
174125
Just mark your integration class with `JupyterLibrary` annotations:
175126

jupyter-lib/api-gradle-plugin/build.gradle.kts

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import org.jetbrains.kotlinx.jupyter.publishing.addPublication
22

33
plugins {
4+
id("com.gradle.plugin-publish") version "0.12.0"
45
id("org.jlleitschuh.gradle.ktlint")
56
`java-gradle-plugin`
67
`kotlin-dsl`
78
id("org.jetbrains.kotlinx.jupyter.publishing")
89
}
910

1011
project.version = rootProject.version
12+
project.group = "org.jetbrains.kotlinx.jupyter"
1113

1214
val junitVersion: String by rootProject
1315

@@ -57,17 +59,38 @@ tasks.test {
5759
}
5860
}
5961

62+
val pluginName = "apiGradlePlugin"
63+
6064
gradlePlugin {
6165
plugins {
62-
create("apiGradlePlugin") {
63-
id = "org.jetbrains.kotlinx.jupyter.api.plugin"
66+
create(pluginName) {
67+
id = "org.jetbrains.kotlin.jupyter.api"
6468
implementationClass = "org.jetbrains.kotlinx.jupyter.api.plugin.ApiGradlePlugin"
6569
}
6670
}
6771
}
6872

73+
pluginBundle {
74+
// These settings are set for the whole plugin bundle
75+
website = "https://github.com/Kotlin/kotlin-jupyter"
76+
vcsUrl = "https://github.com/Kotlin/kotlin-jupyter"
77+
78+
(plugins) {
79+
pluginName {
80+
// id is captured from java-gradle-plugin configuration
81+
displayName = "Kotlin Jupyter kernel integration plugin"
82+
description = "Gradle plugin providing a smooth Jupyter notebooks integration for Kotlin libraries"
83+
tags = listOf("jupyter", "kernel", "kotlin")
84+
}
85+
}
86+
87+
mavenCoordinates {
88+
groupId = "org.jetbrains.kotlin"
89+
}
90+
}
91+
6992
addPublication {
70-
publicationName = "apiGradlePlugin"
93+
publicationName = pluginName
7194
artifactId = "kotlin-jupyter-api-gradle-plugin"
7295
bintrayDescription = "Gradle plugin providing a smooth Jupyter notebooks integration for Kotlin libraries"
7396
bintrayPackageName = artifactId

jupyter-lib/api-gradle-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/plugin/ApiGradlePlugin.kt

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.jupyter.api.plugin
33
import org.gradle.api.Plugin
44
import org.gradle.api.Project
55
import org.gradle.kotlin.dsl.invoke
6+
import org.gradle.kotlin.dsl.maven
67
import org.gradle.kotlin.dsl.register
78
import org.gradle.kotlin.dsl.repositories
89
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin
@@ -23,8 +24,11 @@ class ApiGradlePlugin : Plugin<Project> {
2324

2425
target.repositories {
2526
mavenCentral()
27+
maven("https://kotlin.bintray.com/kotlin-datascience")
2628
}
2729

30+
target.addDependenciesIfNeeded()
31+
2832
target.tasks {
2933
val resourcesTaskName = "processJupyterApiResources"
3034
register<JupyterApiResourcesTask>(resourcesTaskName) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.jetbrains.kotlinx.jupyter.api.plugin
2+
3+
import org.gradle.api.Project
4+
import org.gradle.kotlin.dsl.dependencies
5+
6+
private const val GROUP_ID = "org.jetbrains.kotlinx.jupyter"
7+
8+
private fun Project.getFlag(propertyName: String, default: Boolean = false): Boolean {
9+
return findProperty(propertyName)?.let {
10+
when (it) {
11+
"true", true -> true
12+
"false", false -> false
13+
else -> null
14+
}
15+
} ?: default
16+
}
17+
18+
fun kotlinJupyterApiVersion(): String {
19+
return ApiGradlePlugin::class.java.classLoader.getResource("VERSION")!!.readText()
20+
}
21+
22+
fun Project.addKotlinJupyterApiDependency(version: String? = null) {
23+
val apiVersion = version ?: kotlinJupyterApiVersion()
24+
dependencies {
25+
"compileOnly"("$GROUP_ID:kotlin-jupyter-api:$apiVersion")
26+
}
27+
}
28+
29+
fun Project.addKotlinJupyterScannerDependency(version: String? = null) {
30+
val apiVersion = version ?: kotlinJupyterApiVersion()
31+
val mavenCoordinates = "$GROUP_ID:kotlin-jupyter-api-annotations:$apiVersion"
32+
dependencies {
33+
"implementation"(mavenCoordinates)
34+
"kapt"(mavenCoordinates)
35+
}
36+
}
37+
38+
internal fun Project.addDependenciesIfNeeded() {
39+
if (getFlag("kotlin.jupyter.add.api", true)) {
40+
addKotlinJupyterApiDependency()
41+
}
42+
if (getFlag("kotlin.jupyter.add.scanner", true)) {
43+
addKotlinJupyterScannerDependency()
44+
}
45+
}

jupyter-lib/api-gradle-plugin/src/test/kotlin/org/jetbrains/kotlinx/jupyter/api/plugin/test/ResourcesTaskTests.kt

+8-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ class ResourcesTaskTests {
3838
return GradleRunner.create()
3939
.withProjectDir(projectDir)
4040
.withPluginClasspath()
41-
.withArguments(RESOURCES_TASK_NAME)
41+
.withArguments(
42+
RESOURCES_TASK_NAME,
43+
"-Pkotlin.jupyter.add.api=false",
44+
"-Pkotlin.jupyter.add.scanner=false"
45+
)
46+
.forwardOutput()
4247
.build()
4348
}
4449

@@ -133,13 +138,7 @@ class ResourcesTaskTests {
133138
})
134139
""".trimIndent()
135140
)
136-
137-
GradleRunner.create()
138-
.withProjectDir(projectDir)
139-
.withPluginClasspath()
140-
.withArguments("processJupyterApiResources")
141-
.forwardOutput()
142-
.build()
141+
runResourcesTask()
143142

144143
assertLibrariesJsonContents(
145144
LibrariesScanResult(
@@ -158,7 +157,7 @@ class ResourcesTaskTests {
158157
private val PLUGINS_BLOCK = """
159158
plugins {
160159
id 'org.jetbrains.kotlin.jvm' version '1.4.20'
161-
id 'org.jetbrains.kotlinx.jupyter.api.plugin'
160+
id 'org.jetbrains.kotlin.jupyter.api'
162161
}
163162
""".trimIndent()
164163
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.jetbrains.kotlinx.jupyter.api.plugin.test
2+
3+
import org.jetbrains.kotlinx.jupyter.api.plugin.kotlinJupyterApiVersion
4+
import org.junit.jupiter.api.Test
5+
import kotlin.test.assertTrue
6+
7+
class UtilTests {
8+
9+
@Test
10+
fun testVersion() {
11+
val version = kotlinJupyterApiVersion().trim()
12+
assertTrue(version.isNotEmpty())
13+
}
14+
}

jupyter-lib/api/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/Notebook.kt

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import kotlin.jvm.Throws
66
* [Notebook] is a main entry point for Kotlin Jupyter API
77
*/
88
interface Notebook {
9+
/**
10+
* All executed cells of this notebook
11+
*/
12+
val cellsList: Collection<CodeCell>
13+
914
/**
1015
* Mapping allowing to get cell by execution number
1116
*/

kotlin-jupyter-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/build/distTasks.kt

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ fun ProjectWithOptions.prepareAggregateUploadTasks() {
180180
tasksList.add(taskSpecGetter(taskSpec).taskName)
181181
}
182182

183+
tasksList.add("publishToPluginPortal")
183184
tasksList.add("bintrayUpload")
184185
tasksList.add("publishDocs")
185186

kotlin-jupyter-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/build/util.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ fun <T> Project.getOrInitProperty(name: String, initializer: () -> T): T {
5151
fun Project.getFlag(propertyName: String, default: Boolean = false): Boolean {
5252
return rootProject.findProperty(propertyName)?.let {
5353
when (it) {
54-
"true" -> true
55-
"false" -> false
54+
"true", true -> true
55+
"false", false -> false
5656
else -> null
5757
}
5858
} ?: default

src/main/kotlin/org/jetbrains/kotlinx/jupyter/apiImpl.kt

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class NotebookImpl(
9999
) : Notebook {
100100
private val cells = hashMapOf<Int, CodeCellImpl>()
101101

102+
override val cellsList: Collection<CodeCellImpl>
103+
get() = cells.values
104+
102105
override fun getCell(id: Int): CodeCellImpl {
103106
return cells[id] ?: throw ArrayIndexOutOfBoundsException(
104107
"There is no cell with number '$id'"

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/testUtil.kt

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class TestDisplayHandler(val list: MutableList<Any> = mutableListOf()) : Display
128128
class NotebookMock : Notebook {
129129
private val cells = hashMapOf<Int, CodeCellImpl>()
130130

131+
override val cellsList: Collection<CodeCell>
132+
get() = emptyList()
133+
131134
override fun getCell(id: Int): CodeCellImpl {
132135
return cells[id] ?: throw ArrayIndexOutOfBoundsException(
133136
"There is no cell with number '$id'"

0 commit comments

Comments
 (0)