Polish "Use -parameters compiler arg by default in Gradle builds"
Closes gh-9839
This commit is contained in:
parent
238ef98f8b
commit
70393300c2
|
|
@ -21,6 +21,7 @@ plugin:
|
|||
5. Creates a configuration named `bootArchives` that contains the artifact produced by
|
||||
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.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -125,11 +125,12 @@ final class JavaPluginAction implements PluginApplicationAction {
|
|||
}
|
||||
|
||||
private void configureParametersCompilerArg(Project project) {
|
||||
project.getTasks().withType(JavaCompile.class, compile -> {
|
||||
final List<String> compilerArgs = compile.getOptions().getCompilerArgs();
|
||||
project.getTasks().withType(JavaCompile.class, (compile) -> {
|
||||
List<String> compilerArgs = compile.getOptions().getCompilerArgs();
|
||||
if (!compilerArgs.contains(PARAMETERS_COMPILER_ARG)) {
|
||||
compilerArgs.add(PARAMETERS_COMPILER_ARG);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,33 +75,23 @@ public class JavaPluginActionIntegrationTests {
|
|||
|
||||
@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");
|
||||
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||
.contains("compileJava compiler args: [-parameters]")
|
||||
.contains("compileTestJava compiler args: [-parameters]");
|
||||
}
|
||||
|
||||
// -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");
|
||||
public void javaCompileTasksUseParametersAndAdditionalCompilerFlags() {
|
||||
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||
.contains("compileJava compiler args: [-parameters, -Xlint:all]")
|
||||
.contains("compileTestJava compiler args: [-parameters, -Xlint:all]");
|
||||
}
|
||||
|
||||
// -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");
|
||||
public void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() {
|
||||
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||
.contains("compileJava compiler args: [-Xlint:all]")
|
||||
.contains("compileTestJava compiler args: [-Xlint:all]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -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}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,24 +10,6 @@ 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}"
|
||||
|
|
@ -41,20 +23,3 @@ 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