Merge pull request #9839 from kashike
* gh-9839: Polish "Use -parameters compiler arg by default in Gradle builds" Use -parameters compiler arg by default in Gradle builds
This commit is contained in:
commit
e0a6b16138
|
|
@ -21,6 +21,7 @@ plugin:
|
||||||
5. Creates a configuration named `bootArchives` that contains the artifact produced by
|
5. Creates a configuration named `bootArchives` that contains the artifact produced by
|
||||||
the `bootJar` task.
|
the `bootJar` task.
|
||||||
6. Configures any `JavaCompile` tasks with no configured encoding to use `UTF-8`.
|
6. Configures any `JavaCompile` tasks with no configured encoding to use `UTF-8`.
|
||||||
|
7. Configures any `JavaCompile` tasks to use the `-parameters` compiler argument.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.gradle.plugin;
|
package org.springframework.boot.gradle.plugin;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.gradle.api.Action;
|
import org.gradle.api.Action;
|
||||||
|
|
@ -41,6 +42,7 @@ import org.springframework.boot.gradle.tasks.run.BootRun;
|
||||||
*/
|
*/
|
||||||
final class JavaPluginAction implements PluginApplicationAction {
|
final class JavaPluginAction implements PluginApplicationAction {
|
||||||
|
|
||||||
|
private static final String PARAMETERS_COMPILER_ARG = "-parameters";
|
||||||
private final SinglePublishedArtifact singlePublishedArtifact;
|
private final SinglePublishedArtifact singlePublishedArtifact;
|
||||||
|
|
||||||
JavaPluginAction(SinglePublishedArtifact singlePublishedArtifact) {
|
JavaPluginAction(SinglePublishedArtifact singlePublishedArtifact) {
|
||||||
|
|
@ -60,6 +62,7 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||||
configureArtifactPublication(project, bootJar);
|
configureArtifactPublication(project, bootJar);
|
||||||
configureBootRunTask(project);
|
configureBootRunTask(project);
|
||||||
configureUtf8Encoding(project);
|
configureUtf8Encoding(project);
|
||||||
|
configureParametersCompilerArg(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableJarTask(Project project) {
|
private void disableJarTask(Project project) {
|
||||||
|
|
@ -121,4 +124,13 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void configureParametersCompilerArg(Project project) {
|
||||||
|
project.getTasks().withType(JavaCompile.class, (compile) -> {
|
||||||
|
List<String> compilerArgs = compile.getOptions().getCompilerArgs();
|
||||||
|
if (!compilerArgs.contains(PARAMETERS_COMPILER_ARG)) {
|
||||||
|
compilerArgs.add(PARAMETERS_COMPILER_ARG);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,27 @@ public class JavaPluginActionIntegrationTests {
|
||||||
.contains("compileTestJava = UTF-8");
|
.contains("compileTestJava = UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void javaCompileTasksUseParametersCompilerFlagByDefault() {
|
||||||
|
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||||
|
.contains("compileJava compiler args: [-parameters]")
|
||||||
|
.contains("compileTestJava compiler args: [-parameters]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void javaCompileTasksUseParametersAndAdditionalCompilerFlags() {
|
||||||
|
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||||
|
.contains("compileJava compiler args: [-parameters, -Xlint:all]")
|
||||||
|
.contains("compileTestJava compiler args: [-parameters, -Xlint:all]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() {
|
||||||
|
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||||
|
.contains("compileJava compiler args: [-Xlint:all]")
|
||||||
|
.contains("compileTestJava compiler args: [-Xlint:all]");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void assembleRunsBootJarAndJarIsSkipped() {
|
public void assembleRunsBootJarAndJarIsSkipped() {
|
||||||
BuildResult result = this.gradleBuild.build("assemble");
|
BuildResult result = this.gradleBuild.build("assemble");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
buildscript {
|
||||||
|
dependencies {
|
||||||
|
classpath files(pluginClasspath.split(','))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'org.springframework.boot'
|
||||||
|
apply plugin: 'java'
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.compilerArgs = ['-Xlint:all']
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
task('javaCompileTasksCompilerArgs') {
|
||||||
|
doFirst {
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
println "$name compiler args: ${options.compilerArgs}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
buildscript {
|
||||||
|
dependencies {
|
||||||
|
classpath files(pluginClasspath.split(','))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'org.springframework.boot'
|
||||||
|
apply plugin: 'java'
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.compilerArgs << '-Xlint:all'
|
||||||
|
}
|
||||||
|
|
||||||
|
task('javaCompileTasksCompilerArgs') {
|
||||||
|
doFirst {
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
println "$name compiler args: ${options.compilerArgs}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
buildscript {
|
||||||
|
dependencies {
|
||||||
|
classpath files(pluginClasspath.split(','))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'org.springframework.boot'
|
||||||
|
apply plugin: 'java'
|
||||||
|
|
||||||
|
task('javaCompileTasksCompilerArgs') {
|
||||||
|
doFirst {
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
println "$name compiler args: ${options.compilerArgs}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue