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 all commits
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,29 @@ 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.methods.find { it.name == "getCompilerOptions" }?.invoke(task)
if (compilerOptions != null) {
val freeCompilerArgs = compilerOptions.javaClass.methods.find { it.name == "getFreeCompilerArgs" }
?.invoke(compilerOptions) as? DefaultListProperty<String>
freeCompilerArgs?.addAll(listOf("-Xjsr305=strict", "-Xemit-jvm-type-annotations")) ?:
project.logger.warn("""
Kotlin JVM plugin is applied and 'compilerOption' was not null, but could not acquire the
'freeCompilerArgs' instance from the 'compilerOption' to configure Kotlin compiler options by
adding '-Xjsr305=strict' and '-Xemit-jvm-type-annotations'. To make sure annotation based form
validations are enabled, add the above compiler args in the build file explicitly.""".trimIndent())
} else {
project.logger.warn("""
Kotlin JVM plugin is applied, but could not acquire the 'compilerOption' instance from the
'compileKotlin' task instance to configure Kotlin compiler options by adding '-Xjsr305=strict'
and '-Xemit-jvm-type-annotations' to the 'freeCompilerArgs'. To make sure annotation based form
validations are enabled, add the above compiler args in the build file explicitly.""".trimIndent())
}
}
}

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