Skip to content

Commit

Permalink
editing build so that
Browse files Browse the repository at this point in the history
a) it can build gradle-plugin and compiler-plugin with bootstrap jars without mavenLocal.
b) bootstrap jars are updated before the actual build
  • Loading branch information
Jolanrensen committed Mar 25, 2024
1 parent ffedb29 commit 6b63c96
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 23 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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<BuildConfigExtension>()?.apply {
val projectVersion = Versions.project
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler

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

Expand Down
23 changes: 22 additions & 1 deletion compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,25 @@ fun Test.setLibraryProperty(propName: String, jarName: String) {
?.absolutePath
?: return
systemProperty(propName, path)
}
}

/**
* 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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) })
Expand Down
16 changes: 8 additions & 8 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 22 additions & 6 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,29 @@ dependencies {
}
}

//tasks.withType<ShadowJar> {
// isZip64 = true
// archiveClassifier = ""
//}

kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(Versions.jvmTarget)
}
}
}

/**
* 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)
}
Binary file added gradle/bootstraps/compiler-plugin.jar
Binary file not shown.
Binary file added gradle/bootstraps/gradle-plugin.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions jupyter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6b63c96

Please sign in to comment.