diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 80cf9542..11cb8db0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,11 +36,10 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- - - name: Publish plugins to maven local + - name: Build the plugins first run: > ./gradlew - compiler-plugin:publishToMavenLocal - gradle-plugin:publishToMavenLocal + updateBootstrapVersion - name: Build with Gradle uses: gradle/gradle-build-action@v2 diff --git a/build.gradle.kts b/build.gradle.kts index feab33b2..57a5e14b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,6 +12,10 @@ buildscript { dependencies { classpath(jcp) classpath(mavenPublish) + + // Allows the project to use the gradle plugin without mavenLocal + // Kept up-to-date by :gradle-plugin:updateBootstrapVersion + classpath(files("${project.rootDir.absolutePath}/gradle/bootstraps/gradle-plugin.jar")) } } @@ -21,9 +25,6 @@ plugins { idea kotlin version Versions.kotlin apply false buildconfig version Versions.buildconfig apply false - - // Needs to be installed in the local maven repository - kotlinSparkApi version Versions.kotlinSparkApiGradlePlugin apply false } group = Versions.groupID @@ -125,6 +126,13 @@ allprojects { } subprojects { + // Adding the bootstraps directory to the repositories of the subprojects, so that + // the bootstrap version of compiler-plugin.jar can be found and used by the gradle-plugin + // without mavenLocal + repositories.flatDir { + dirs("${project.rootDir.absolutePath}/gradle/bootstraps") + } + afterEvaluate { extensions.findByType()?.apply { val projectVersion = Versions.project diff --git a/buildSrc/src/main/kotlin/Helpers.kt b/buildSrc/src/main/kotlin/Helpers.kt index cc313776..6c903b17 100644 --- a/buildSrc/src/main/kotlin/Helpers.kt +++ b/buildSrc/src/main/kotlin/Helpers.kt @@ -3,6 +3,7 @@ import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.dsl.DependencyHandler interface Dsl { + @Suppress("UNCHECKED_CAST") operator fun invoke(block: T.() -> Unit) = block(this as T) } diff --git a/compiler-plugin/build.gradle.kts b/compiler-plugin/build.gradle.kts index 629b74ad..02aac811 100644 --- a/compiler-plugin/build.gradle.kts +++ b/compiler-plugin/build.gradle.kts @@ -102,4 +102,25 @@ fun Test.setLibraryProperty(propName: String, jarName: String) { ?.absolutePath ?: return systemProperty(propName, path) -} \ No newline at end of file +} + +/** + * Copies the built jar file to the gradle/bootstraps directory. + * This allows the project to use the compiler plugin without mavenLocal. + */ +val updateBootstrapVersion by tasks.creating(Copy::class) { + group = "build" + dependsOn(tasks.jar) + + val jarFile = tasks.jar.get().outputs.files.files.single { + it.extension == "jar" && it.name.startsWith("compiler-plugin") + } + from(jarFile) + rename { "compiler-plugin.jar" } + into(project.rootDir.resolve("gradle/bootstraps")) + outputs.upToDateWhen { false } +} + +tasks.build { + finalizedBy(updateBootstrapVersion) +} diff --git a/compiler-plugin/src/main/kotlin/org/jetbrains/kotlinx/spark/api/compilerPlugin/ir/DataClassSparkifyGenerator.kt b/compiler-plugin/src/main/kotlin/org/jetbrains/kotlinx/spark/api/compilerPlugin/ir/DataClassSparkifyGenerator.kt index 0438b42b..7d3992dc 100644 --- a/compiler-plugin/src/main/kotlin/org/jetbrains/kotlinx/spark/api/compilerPlugin/ir/DataClassSparkifyGenerator.kt +++ b/compiler-plugin/src/main/kotlin/org/jetbrains/kotlinx/spark/api/compilerPlugin/ir/DataClassSparkifyGenerator.kt @@ -96,6 +96,7 @@ class DataClassSparkifyGenerator( * ) * ``` */ + @OptIn(UnsafeDuringIrConstructionAPI::class) override fun visitProperty(declaration: IrProperty) { val origin = declaration.parent as? IrClass ?: return super.visitProperty(declaration) if (sparkifyAnnotationFqNames.none { origin.hasAnnotation(FqName(it)) }) diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 7f371ecc..4a0a2179 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -1,17 +1,17 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - // Needs to be installed in the local maven repository + // Needs to be installed in the local maven repository or have the bootstrap jar on the classpath id("org.jetbrains.kotlinx.spark.api") - kotlin + kotlin("jvm") } -//kotlinSparkApi { -// enabled = true -// sparkifyAnnotationFqNames = listOf( -// "org.jetbrains.kotlinx.spark.api.plugin.annotations.Sparkify", -// ) -//} +kotlinSparkApi { + enabled = true + sparkifyAnnotationFqNames = listOf( + "org.jetbrains.kotlinx.spark.api.plugin.annotations.Sparkify", + ) +} group = Versions.groupID version = Versions.project diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts index 9facda3f..fb77282e 100644 --- a/gradle-plugin/build.gradle.kts +++ b/gradle-plugin/build.gradle.kts @@ -49,13 +49,29 @@ dependencies { } } -//tasks.withType { -// isZip64 = true -// archiveClassifier = "" -//} - kotlin { jvmToolchain { languageVersion = JavaLanguageVersion.of(Versions.jvmTarget) } -} \ No newline at end of file +} + +/** + * Copies the built jar file to the gradle/bootstraps directory. + * This allows the project to use the gradle plugin without mavenLocal. + */ +val updateBootstrapVersion by tasks.creating(Copy::class) { + group = "build" + dependsOn(tasks.jar) + + val jarFile = tasks.jar.get().outputs.files.files.single { + it.extension == "jar" && it.name.startsWith("gradle-plugin") + } + from(jarFile) + rename { "gradle-plugin.jar" } + into(project.rootDir.resolve("gradle/bootstraps")) + outputs.upToDateWhen { false } +} + +tasks.build { + finalizedBy(updateBootstrapVersion) +} diff --git a/gradle/bootstraps/compiler-plugin.jar b/gradle/bootstraps/compiler-plugin.jar new file mode 100644 index 00000000..9274a64d Binary files /dev/null and b/gradle/bootstraps/compiler-plugin.jar differ diff --git a/gradle/bootstraps/gradle-plugin.jar b/gradle/bootstraps/gradle-plugin.jar new file mode 100644 index 00000000..a10e11bf Binary files /dev/null and b/gradle/bootstraps/gradle-plugin.jar differ diff --git a/jupyter/build.gradle.kts b/jupyter/build.gradle.kts index 57adf168..fb5e90de 100644 --- a/jupyter/build.gradle.kts +++ b/jupyter/build.gradle.kts @@ -1,10 +1,9 @@ -@file:Suppress("UnstableApiUsage", "NOTHING_TO_INLINE") +@file:Suppress("UnstableApiUsage") import com.igormaznitsa.jcp.gradle.JcpTask import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinJvm import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { scala