@@ -2,82 +2,39 @@ package org.jetbrains.kotlinx.jupyter.api.plugin
2
2
3
3
import org.gradle.api.Project
4
4
import org.gradle.kotlin.dsl.dependencies
5
- import org.gradle.kotlin.dsl.findByType
6
- import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
7
- import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
8
- import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.whenAdded
9
- import java.util.Locale
10
-
11
- private fun Project.configureDependency (scope : String , dependencyNotation : Any ) {
12
- // apply configuration to JVM-only project
13
- plugins.withId(" org.jetbrains.kotlin.jvm" ) {
14
- val configuration = project.configurations.findByName(scope)
15
- ? : error(" $scope configuration is not resolved for a Kotlin-JVM project" )
16
- dependencies {
17
- configuration.invoke(dependencyNotation)
18
- }
19
- }
20
- // apply only to multiplatform plugin
21
- plugins.withId(" org.jetbrains.kotlin.multiplatform" ) {
22
- extensions.findByType<KotlinMultiplatformExtension >()?.apply {
23
- targets.whenAdded(
24
- { it is KotlinJvmTarget },
25
- {
26
- val jvmTargetName = it.name
27
- val configuration = project.configurations.findByName(jvmTargetName + scope.capitalize(Locale .ROOT ))
28
- ? : error(" $scope configuration is not resolved for a multiplatform project" )
29
- dependencies {
30
- configuration.invoke(dependencyNotation)
31
- }
32
- }
33
- )
34
- }
35
- }
36
- }
5
+ import org.jetbrains.kotlinx.jupyter.api.plugin.util.configureDependency
6
+ import org.jetbrains.kotlinx.jupyter.api.plugin.util.kernelDependency
7
+ import org.jetbrains.kotlinx.jupyter.api.plugin.util.propertyByFlag
8
+ import org.jetbrains.kotlinx.jupyter.api.plugin.util.whenAdded
37
9
38
10
class KotlinJupyterPluginExtension (
39
11
private val project : Project
40
12
) {
13
+ private val enableApiDependency = project.propertyByFlag(" kotlin.jupyter.add.api" , true )
14
+ private val enableScannerDependency = project.propertyByFlag(" kotlin.jupyter.add.scanner" , true )
15
+ private val enableTestKitDependency = project.propertyByFlag(" kotlin.jupyter.add.testkit" , true )
16
+
17
+ internal fun addDependenciesIfNeeded () {
18
+ if (enableApiDependency.get()) addApiDependency()
19
+ if (enableScannerDependency.get()) addScannerDependency()
20
+ if (enableTestKitDependency.get()) addTestKitDependency()
21
+ }
22
+
41
23
fun addApiDependency (version : String? = null) = with (project) {
42
- val apiVersion = version ? : apiVersion()
43
- configureDependency(" compileOnly" , " $GROUP_ID :kotlin-jupyter-api:$apiVersion " )
24
+ configureDependency(" compileOnly" , kernelDependency(" api" , version))
44
25
}
45
26
46
27
fun addScannerDependency (version : String? = null) = with (project) {
47
28
configurations.whenAdded({ it.name == " kapt" }) { kaptConf ->
48
- val apiVersion = version ? : apiVersion()
49
- val mavenCoordinates = " $GROUP_ID :kotlin-jupyter-api-annotations:$apiVersion "
29
+ val annotationsDependency = kernelDependency(" api-annotations" , version)
50
30
dependencies {
51
- kaptConf(mavenCoordinates )
31
+ kaptConf(annotationsDependency )
52
32
}
53
- configureDependency(" implementation" , mavenCoordinates )
33
+ configureDependency(" implementation" , annotationsDependency )
54
34
}
55
35
}
56
36
57
- internal fun addDependenciesIfNeeded () {
58
- if (project.getFlag(" kotlin.jupyter.add.api" , true )) {
59
- addApiDependency()
60
- }
61
- if (project.getFlag(" kotlin.jupyter.add.scanner" , true )) {
62
- addScannerDependency()
63
- }
64
- }
65
-
66
- companion object {
67
- private const val GROUP_ID = " org.jetbrains.kotlinx"
68
-
69
- private fun Project.getFlag (propertyName : String , default : Boolean = false): Boolean {
70
- return findProperty(propertyName)?.let {
71
- when (it) {
72
- " true" , true -> true
73
- " false" , false -> false
74
- else -> null
75
- }
76
- } ? : default
77
- }
78
-
79
- fun apiVersion (): String {
80
- return ApiGradlePlugin ::class .java.classLoader.getResource(" VERSION" )!! .readText()
81
- }
37
+ fun addTestKitDependency (version : String? = null) = with (project) {
38
+ configureDependency(" testImplementation" , kernelDependency(" test-kit" , version))
82
39
}
83
40
}
0 commit comments