Skip to content

Commit 6b63c96

Browse files
committed
editing build so that
a) it can build gradle-plugin and compiler-plugin with bootstrap jars without mavenLocal. b) bootstrap jars are updated before the actual build
1 parent ffedb29 commit 6b63c96

File tree

10 files changed

+68
-23
lines changed

10 files changed

+68
-23
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ jobs:
3636
restore-keys: |
3737
${{ runner.os }}-gradle-
3838
39-
- name: Publish plugins to maven local
39+
- name: Build the plugins first
4040
run: >
4141
./gradlew
42-
compiler-plugin:publishToMavenLocal
43-
gradle-plugin:publishToMavenLocal
42+
updateBootstrapVersion
4443
4544
- name: Build with Gradle
4645
uses: gradle/gradle-build-action@v2

build.gradle.kts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ buildscript {
1212
dependencies {
1313
classpath(jcp)
1414
classpath(mavenPublish)
15+
16+
// Allows the project to use the gradle plugin without mavenLocal
17+
// Kept up-to-date by :gradle-plugin:updateBootstrapVersion
18+
classpath(files("${project.rootDir.absolutePath}/gradle/bootstraps/gradle-plugin.jar"))
1519
}
1620
}
1721

@@ -21,9 +25,6 @@ plugins {
2125
idea
2226
kotlin version Versions.kotlin apply false
2327
buildconfig version Versions.buildconfig apply false
24-
25-
// Needs to be installed in the local maven repository
26-
kotlinSparkApi version Versions.kotlinSparkApiGradlePlugin apply false
2728
}
2829

2930
group = Versions.groupID
@@ -125,6 +126,13 @@ allprojects {
125126
}
126127

127128
subprojects {
129+
// Adding the bootstraps directory to the repositories of the subprojects, so that
130+
// the bootstrap version of compiler-plugin.jar can be found and used by the gradle-plugin
131+
// without mavenLocal
132+
repositories.flatDir {
133+
dirs("${project.rootDir.absolutePath}/gradle/bootstraps")
134+
}
135+
128136
afterEvaluate {
129137
extensions.findByType<BuildConfigExtension>()?.apply {
130138
val projectVersion = Versions.project

buildSrc/src/main/kotlin/Helpers.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.gradle.api.artifacts.ProjectDependency
33
import org.gradle.api.artifacts.dsl.DependencyHandler
44

55
interface Dsl<T> {
6+
@Suppress("UNCHECKED_CAST")
67
operator fun invoke(block: T.() -> Unit) = block(this as T)
78
}
89

compiler-plugin/build.gradle.kts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,25 @@ fun Test.setLibraryProperty(propName: String, jarName: String) {
102102
?.absolutePath
103103
?: return
104104
systemProperty(propName, path)
105-
}
105+
}
106+
107+
/**
108+
* Copies the built jar file to the gradle/bootstraps directory.
109+
* This allows the project to use the compiler plugin without mavenLocal.
110+
*/
111+
val updateBootstrapVersion by tasks.creating(Copy::class) {
112+
group = "build"
113+
dependsOn(tasks.jar)
114+
115+
val jarFile = tasks.jar.get().outputs.files.files.single {
116+
it.extension == "jar" && it.name.startsWith("compiler-plugin")
117+
}
118+
from(jarFile)
119+
rename { "compiler-plugin.jar" }
120+
into(project.rootDir.resolve("gradle/bootstraps"))
121+
outputs.upToDateWhen { false }
122+
}
123+
124+
tasks.build {
125+
finalizedBy(updateBootstrapVersion)
126+
}

compiler-plugin/src/main/kotlin/org/jetbrains/kotlinx/spark/api/compilerPlugin/ir/DataClassSparkifyGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class DataClassSparkifyGenerator(
9696
* )
9797
* ```
9898
*/
99+
@OptIn(UnsafeDuringIrConstructionAPI::class)
99100
override fun visitProperty(declaration: IrProperty) {
100101
val origin = declaration.parent as? IrClass ?: return super.visitProperty(declaration)
101102
if (sparkifyAnnotationFqNames.none { origin.hasAnnotation(FqName(it)) })

examples/build.gradle.kts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
plugins {
4-
// Needs to be installed in the local maven repository
4+
// Needs to be installed in the local maven repository or have the bootstrap jar on the classpath
55
id("org.jetbrains.kotlinx.spark.api")
6-
kotlin
6+
kotlin("jvm")
77
}
88

9-
//kotlinSparkApi {
10-
// enabled = true
11-
// sparkifyAnnotationFqNames = listOf(
12-
// "org.jetbrains.kotlinx.spark.api.plugin.annotations.Sparkify",
13-
// )
14-
//}
9+
kotlinSparkApi {
10+
enabled = true
11+
sparkifyAnnotationFqNames = listOf(
12+
"org.jetbrains.kotlinx.spark.api.plugin.annotations.Sparkify",
13+
)
14+
}
1515

1616
group = Versions.groupID
1717
version = Versions.project

gradle-plugin/build.gradle.kts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,29 @@ dependencies {
4949
}
5050
}
5151

52-
//tasks.withType<ShadowJar> {
53-
// isZip64 = true
54-
// archiveClassifier = ""
55-
//}
56-
5752
kotlin {
5853
jvmToolchain {
5954
languageVersion = JavaLanguageVersion.of(Versions.jvmTarget)
6055
}
61-
}
56+
}
57+
58+
/**
59+
* Copies the built jar file to the gradle/bootstraps directory.
60+
* This allows the project to use the gradle plugin without mavenLocal.
61+
*/
62+
val updateBootstrapVersion by tasks.creating(Copy::class) {
63+
group = "build"
64+
dependsOn(tasks.jar)
65+
66+
val jarFile = tasks.jar.get().outputs.files.files.single {
67+
it.extension == "jar" && it.name.startsWith("gradle-plugin")
68+
}
69+
from(jarFile)
70+
rename { "gradle-plugin.jar" }
71+
into(project.rootDir.resolve("gradle/bootstraps"))
72+
outputs.upToDateWhen { false }
73+
}
74+
75+
tasks.build {
76+
finalizedBy(updateBootstrapVersion)
77+
}

gradle/bootstraps/compiler-plugin.jar

45.9 KB
Binary file not shown.

gradle/bootstraps/gradle-plugin.jar

9.18 KB
Binary file not shown.

jupyter/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
@file:Suppress("UnstableApiUsage", "NOTHING_TO_INLINE")
1+
@file:Suppress("UnstableApiUsage")
22

33
import com.igormaznitsa.jcp.gradle.JcpTask
44
import com.vanniktech.maven.publish.JavadocJar.Dokka
55
import com.vanniktech.maven.publish.KotlinJvm
66
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
7-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
87

98
plugins {
109
scala

0 commit comments

Comments
 (0)