Use -parameters compiler arg by default in Gradle builds
See gh-9839
This commit is contained in:
parent
8ab12d909e
commit
238ef98f8b
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.gradle.plugin;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
|
|
@ -41,6 +42,7 @@ import org.springframework.boot.gradle.tasks.run.BootRun;
|
|||
*/
|
||||
final class JavaPluginAction implements PluginApplicationAction {
|
||||
|
||||
private static final String PARAMETERS_COMPILER_ARG = "-parameters";
|
||||
private final SinglePublishedArtifact singlePublishedArtifact;
|
||||
|
||||
JavaPluginAction(SinglePublishedArtifact singlePublishedArtifact) {
|
||||
|
|
@ -60,6 +62,7 @@ final class JavaPluginAction implements PluginApplicationAction {
|
|||
configureArtifactPublication(project, bootJar);
|
||||
configureBootRunTask(project);
|
||||
configureUtf8Encoding(project);
|
||||
configureParametersCompilerArg(project);
|
||||
}
|
||||
|
||||
private void disableJarTask(Project project) {
|
||||
|
|
@ -121,4 +124,12 @@ final class JavaPluginAction implements PluginApplicationAction {
|
|||
}));
|
||||
}
|
||||
|
||||
private void configureParametersCompilerArg(Project project) {
|
||||
project.getTasks().withType(JavaCompile.class, compile -> {
|
||||
final List<String> compilerArgs = compile.getOptions().getCompilerArgs();
|
||||
if (!compilerArgs.contains(PARAMETERS_COMPILER_ARG)) {
|
||||
compilerArgs.add(PARAMETERS_COMPILER_ARG);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,37 @@ public class JavaPluginActionIntegrationTests {
|
|||
.contains("compileTestJava = UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaCompileTasksUseParametersCompilerFlagByDefault() {
|
||||
assertThat(this.gradleBuild.build("javaParametersCompilerArg", "-PapplyJavaPlugin")
|
||||
.getOutput()).contains("compileJava has -parameters by default = true")
|
||||
.contains("compileTestJava has -parameters by default = true");
|
||||
}
|
||||
|
||||
// -parameters and an additional compiler arg
|
||||
@Test
|
||||
public void javaCompileTasksUseParametersCompilerFlagWhenOtherAdded() {
|
||||
assertThat(this.gradleBuild.build("javaParametersCompilerArg", "-PapplyJavaPlugin", "-PparametersAddOther")
|
||||
.getOutput()).contains("compileJava has -parameters when another arg has been added = true")
|
||||
.contains("compileTestJava has -parameters when another arg has been added = true");
|
||||
}
|
||||
|
||||
// -parameters removed
|
||||
@Test
|
||||
public void javaCompileTasksDoesNotUseParametersWhenParametersRemoved() {
|
||||
assertThat(this.gradleBuild.build("javaParametersCompilerArg", "-PapplyJavaPlugin", "-PparametersRemove")
|
||||
.getOutput()).contains("compileJava has -parameters when removed = false")
|
||||
.contains("compileTestJava has -parameters when removed = false");
|
||||
}
|
||||
|
||||
// compiler args cleared
|
||||
@Test
|
||||
public void javaCompileTasksDoesNotUseParametersWhenArgsCleared() {
|
||||
assertThat(this.gradleBuild.build("javaParametersCompilerArg", "-PapplyJavaPlugin", "-PparametersClear")
|
||||
.getOutput()).contains("compileJava has -parameters when cleared = false")
|
||||
.contains("compileTestJava has -parameters when cleared = false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assembleRunsBootJarAndJarIsSkipped() {
|
||||
BuildResult result = this.gradleBuild.build("assemble");
|
||||
|
|
|
|||
|
|
@ -10,6 +10,24 @@ if (project.hasProperty('applyJavaPlugin')) {
|
|||
apply plugin: 'java'
|
||||
}
|
||||
|
||||
if (project.hasProperty('parametersRemove')) {
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs.remove('-parameters')
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('parametersClear')) {
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs.clear()
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('parametersAddOther')) {
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs.add('-Xlint:all')
|
||||
}
|
||||
}
|
||||
|
||||
task('taskExists') {
|
||||
doFirst {
|
||||
println "$taskName exists = ${tasks.findByName(taskName) != null}"
|
||||
|
|
@ -23,3 +41,20 @@ task('javaCompileEncoding') {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
task('javaParametersCompilerArg') {
|
||||
doFirst {
|
||||
tasks.withType(JavaCompile) {
|
||||
def contains = options.compilerArgs.contains('-parameters')
|
||||
if (project.hasProperty('parametersRemove')) {
|
||||
println "$name has -parameters when removed = ${contains}"
|
||||
} else if (project.hasProperty('parametersClear')) {
|
||||
println "$name has -parameters when cleared = ${contains}"
|
||||
} else if (project.hasProperty('parametersAddOther')) {
|
||||
println "$name has -parameters when another arg has been added = ${contains}"
|
||||
} else {
|
||||
println "$name has -parameters by default = ${contains}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue