Skip to content

Ensure kotlin compiler includes method param names #12641

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

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,10 @@ JSON request body. When exposed via JMX, the parameters are mapped to the parame
the MBean's operations. Parameters are required by default. They can be made optional
by annotating them with `@org.springframework.lang.Nullable`.

NOTE: To allow the input to be mapped to the operation method's parameters, code
implementing an endpoint should be compiled with `-parameters`. This will happen
automatically if you are using Spring Boot's Gradle plugin or if you are using Maven
and `spring-boot-starter-parent`.

NOTE: To allow the input to be mapped to the operation method's parameters, java code
implementing an endpoint should be compiled with `-parameters`, and kotlin code should
be compiled with `-java-parameters`. This will happen automatically if you are using
Spring Boot's Gradle plugin or if you are using Maven and `spring-boot-starter-parent`.


[[production-ready-endpoints-custom-input-conversion]]
Expand Down
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<jvmTarget>${java.version}</jvmTarget>
<apiVersion>1.1</apiVersion>
<languageVersion>1.1</languageVersion>
<javaParameters>true</javaParameters>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>${java.version}</jvmTarget>
<javaParameters>true</javaParameters>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugin:
the `bootJar` task.
6. Configures any `JavaCompile` tasks with no configured encoding to use `UTF-8`.
7. Configures any `JavaCompile` tasks to use the `-parameters` compiler argument.

8. Configures any `KotlinCompile` tasks to use the `-java-parameters` compiler argument.


[[reacting-to-other-plugins-kotlin]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.gradle.api.Project;
import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper;
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;

/**
* {@link PluginApplicationAction} that reacts to Kotlin's Gradle plugin being applied by
Expand All @@ -39,6 +40,13 @@ public void execute(Project project) {
if (!extraProperties.has("kotlin.version")) {
extraProperties.set("kotlin.version", kotlinVersion);
}
enableJavaParametersOption(project);
}

private void enableJavaParametersOption(Project project) {
project.getTasks().withType(KotlinCompile.class, (compile) -> {
compile.getKotlinOptions().setJavaParameters(true);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ public void kotlinVersionMatchesKotlinPluginVersion() {
.containsPattern("org.jetbrains.kotlin:kotlin-stdlib-jdk8:* -> 1.2.10");
}

@Test
public void kotlinCompileTasksUseJavaParametersFlagByDefault() {
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
.contains("compileKotlin java parameters: true")
.contains("compileTestKotlin java parameters: true");
}

@Test
public void kotlinCompileTasksCanOverrideDefaultJavaParametersFlag() {
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
.contains("compileKotlin java parameters: false")
.contains("compileTestKotlin java parameters: false");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
buildscript {
dependencies {
classpath files(pluginClasspath.split(','))
}
}

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.2.10'
}

apply plugin: 'org.springframework.boot'

import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

tasks.withType(KotlinCompile) {
kotlinOptions.javaParameters = false
}

task('kotlinCompileTasksJavaParameters') {
doFirst {
tasks.withType(KotlinCompile) {
println "$name java parameters: ${kotlinOptions.javaParameters}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
buildscript {
dependencies {
classpath files(pluginClasspath.split(','))
}
}

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.2.10'
}

apply plugin: 'org.springframework.boot'

import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

task('kotlinCompileTasksJavaParameters') {
doFirst {
tasks.withType(KotlinCompile) {
println "$name java parameters: ${kotlinOptions.javaParameters}"
}
}
}