Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add kotlin compiler args to gradle plugin #3156

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/java/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id 'maven-publish'
id 'idea'
id 'com.gradle.plugin-publish' version '0.11.0'
id 'org.jetbrains.kotlin.jvm' version '1.9.20-Beta2'
id 'org.jetbrains.kotlin.jvm' version '1.9.25'
id 'org.jetbrains.dokka' version '1.9.0'
}

Expand Down Expand Up @@ -66,14 +66,14 @@ repositories {
}

dependencies {
implementation('org.jetbrains.kotlin:kotlin-stdlib:1.9.20')
implementation('org.jetbrains.kotlin:kotlin-stdlib:1.9.25')
implementation("com.vaadin:hilla-endpoint:$version")
implementation("com.vaadin:hilla-engine-core:$version")
implementation("com.vaadin:flow-gradle-plugin:$flowVersion")
implementation("org.springframework.boot:spring-boot-loader-tools:$springBootVersion")

testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-test:1.9.20")
testImplementation("org.jetbrains.kotlin:kotlin-test:1.9.25")
}

idea {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.vaadin.hilla.engine.EngineConfiguration
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.internal.provider.DefaultListProperty
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.SourceSet
Expand Down Expand Up @@ -56,6 +57,16 @@ public class HillaPlugin : Plugin<Project> {
}
}

// Configure Kotlin-specific tasks only if Kotlin JVM plugin is applied
project.plugins.withId("org.jetbrains.kotlin.jvm") {
project.tasks.named("compileKotlin").configure { task ->
val compilerOptions = task.javaClass.getMethod("getCompilerOptions").invoke(task)
val freeCompilerArgs = compilerOptions.javaClass.getMethod("getFreeCompilerArgs")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if one of those invokes can return null

Copy link
Contributor Author

@taefi taefi Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, when the Kotlin jvm plugin is applied, the compileKotlin task and its options cannot be null. But, because of executing methods dynamically using reflection, added null check guards for cases such as API removal in future, or other possible edge cases we are not aware of atm.

.invoke(compilerOptions) as DefaultListProperty<String>
freeCompilerArgs.addAll(listOf("-Xjsr305=strict", "-Xemit-jvm-type-annotations"))
}
}

project.tasks.withType(Jar::class.java) { task: Jar ->
task.mustRunAfter("vaadinBuildFrontend")
}
Expand Down
Loading