Merge branch '2.7.x' into 3.0.x

Closes gh-34460
pull/34503/head
Andy Wilkinson 2 years ago
commit 03dd666818

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,6 +31,7 @@ public class BootRunClasspathApplication {
} }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Main class name = " + BootRunClasspathApplication.class.getName());
int i = 1; int i = 1;
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator)) { for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator)) {
System.out.println(i++ + ". " + entry); System.out.println(i++ + ". " + entry);

@ -47,53 +47,46 @@ class JavaPluginActionIntegrationTests {
@TestTemplate @TestTemplate
void noBootJarTaskWithoutJavaPluginApplied() { void noBootJarTaskWithoutJavaPluginApplied() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar").getOutput()) assertThat(this.gradleBuild.build("tasks").getOutput()).doesNotContain("bootJar");
.contains("bootJar exists = false");
} }
@TestTemplate @TestTemplate
void applyingJavaPluginCreatesBootJarTask() { void applyingJavaPluginCreatesBootJarTask() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin").getOutput()) assertThat(this.gradleBuild.build("tasks").getOutput()).contains("bootJar");
.contains("bootJar exists = true");
} }
@TestTemplate @TestTemplate
void noBootRunTaskWithoutJavaPluginApplied() { void noBootRunTaskWithoutJavaPluginApplied() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun").getOutput()) assertThat(this.gradleBuild.build("tasks").getOutput()).doesNotContain("bootRun");
.contains("bootRun exists = false");
} }
@TestTemplate @TestTemplate
void applyingJavaPluginCreatesBootRunTask() { void applyingJavaPluginCreatesBootRunTask() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin").getOutput()) assertThat(this.gradleBuild.build("tasks").getOutput()).contains("bootRun");
.contains("bootRun exists = true");
} }
@TestTemplate @TestTemplate
void javaCompileTasksUseUtf8Encoding() { void javaCompileTasksUseUtf8Encoding() {
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin").getOutput()) assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava = UTF-8")
.contains("compileJava = UTF-8")
.contains("compileTestJava = UTF-8"); .contains("compileTestJava = UTF-8");
} }
@TestTemplate @TestTemplate
void javaCompileTasksUseParametersCompilerFlagByDefault() { void javaCompileTasksUseParametersCompilerFlagByDefault() {
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput()) assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava compiler args: [-parameters]")
.contains("compileJava compiler args: [-parameters]")
.contains("compileTestJava compiler args: [-parameters]"); .contains("compileTestJava compiler args: [-parameters]");
} }
@TestTemplate @TestTemplate
void javaCompileTasksUseParametersAndAdditionalCompilerFlags() { void javaCompileTasksUseParametersAndAdditionalCompilerFlags() {
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput()) assertThat(this.gradleBuild.build("build").getOutput())
.contains("compileJava compiler args: [-parameters, -Xlint:all]") .contains("compileJava compiler args: [-parameters, -Xlint:all]")
.contains("compileTestJava compiler args: [-parameters, -Xlint:all]"); .contains("compileTestJava compiler args: [-parameters, -Xlint:all]");
} }
@TestTemplate @TestTemplate
void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() { void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() {
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput()) assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava compiler args: [-Xlint:all]")
.contains("compileJava compiler args: [-Xlint:all]")
.contains("compileTestJava compiler args: [-Xlint:all]"); .contains("compileTestJava compiler args: [-Xlint:all]");
} }
@ -139,16 +132,12 @@ class JavaPluginActionIntegrationTests {
@TestTemplate @TestTemplate
void applyingJavaPluginCreatesDevelopmentOnlyConfiguration() { void applyingJavaPluginCreatesDevelopmentOnlyConfiguration() {
assertThat(this.gradleBuild assertThat(this.gradleBuild.build("build").getOutput()).contains("developmentOnly exists = true");
.build("configurationExists", "-PconfigurationName=developmentOnly", "-PapplyJavaPlugin")
.getOutput()).contains("developmentOnly exists = true");
} }
@TestTemplate @TestTemplate
void productionRuntimeClasspathIsConfiguredWithAttributes() { void productionRuntimeClasspathIsConfiguredWithAttributes() {
assertThat(this.gradleBuild assertThat(this.gradleBuild.build("build").getOutput()).contains("3 productionRuntimeClasspath attributes:")
.build("configurationAttributes", "-PconfigurationName=productionRuntimeClasspath", "-PapplyJavaPlugin")
.getOutput()).contains("3 productionRuntimeClasspath attributes:")
.contains("org.gradle.usage: java-runtime") .contains("org.gradle.usage: java-runtime")
.contains("org.gradle.libraryelements: jar") .contains("org.gradle.libraryelements: jar")
.contains("org.gradle.dependency.bundling: external"); .contains("org.gradle.dependency.bundling: external");
@ -156,18 +145,11 @@ class JavaPluginActionIntegrationTests {
@TestTemplate @TestTemplate
void productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath() { void productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath() {
String runtime = this.gradleBuild String output = this.gradleBuild.build("build").getOutput();
.build("configurationResolvabilityAndConsumability", "-PconfigurationName=runtimeClasspath", assertThat(output).contains("runtimeClasspath canBeResolved: true");
"-PapplyJavaPlugin") assertThat(output).contains("runtimeClasspath canBeConsumed: false");
.getOutput(); assertThat(output).contains("productionRuntimeClasspath canBeResolved: true");
assertThat(runtime).contains("canBeResolved: true"); assertThat(output).contains("productionRuntimeClasspath canBeConsumed: false");
assertThat(runtime).contains("canBeConsumed: false");
String productionRuntime = this.gradleBuild
.build("configurationResolvabilityAndConsumability", "-PconfigurationName=productionRuntimeClasspath",
"-PapplyJavaPlugin")
.getOutput();
assertThat(productionRuntime).contains("canBeResolved: true");
assertThat(productionRuntime).contains("canBeConsumed: false");
} }
@TestTemplate @TestTemplate

@ -22,7 +22,6 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.TestTemplate;
import org.springframework.boot.gradle.junit.GradleCompatibility; import org.springframework.boot.gradle.junit.GradleCompatibility;
@ -45,9 +44,7 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
@TestTemplate @TestTemplate
void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() { void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() {
BuildResult build = this.gradleBuild.build("resolveResolvableCopyOfUnresolvableConfiguration"); this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("8.0").build("build");
assertThat(build.task(":resolveResolvableCopyOfUnresolvableConfiguration").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
} }
@TestTemplate @TestTemplate

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,10 +16,14 @@
package org.springframework.boot.gradle.tasks.bundling; package org.springframework.boot.gradle.tasks.bundling;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.assertj.core.api.Assumptions;
import org.gradle.util.GradleVersion;
import org.springframework.boot.gradle.junit.GradleCompatibility; import org.springframework.boot.gradle.junit.GradleCompatibility;
/** /**
@ -42,4 +46,25 @@ class BootWarIntegrationTests extends AbstractBootArchiveIntegrationTests {
return contents.toArray(new String[0]); return contents.toArray(new String[0]);
} }
@Override
void multiModuleImplicitLayers() throws IOException {
whenTestingWithTheConfigurationCacheAssumeThatTheGradleVersionIsLessThan8();
super.multiModuleImplicitLayers();
}
@Override
void multiModuleCustomLayers() throws IOException {
whenTestingWithTheConfigurationCacheAssumeThatTheGradleVersionIsLessThan8();
super.multiModuleCustomLayers();
}
private void whenTestingWithTheConfigurationCacheAssumeThatTheGradleVersionIsLessThan8() {
if (this.gradleBuild.isConfigurationCache()) {
// With Gradle 8.0, a configuration cache bug prevents ResolvedDependencies
// from processing dependencies on the runtime classpath
Assumptions.assumeThat(GradleVersion.version(this.gradleBuild.getGradleVersion()))
.isLessThan(GradleVersion.version("8.0"));
}
}
} }

@ -24,8 +24,10 @@ import java.util.jar.Attributes;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import org.assertj.core.api.Assumptions;
import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome; import org.gradle.testkit.runner.TaskOutcome;
import org.gradle.util.GradleVersion;
import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.TestTemplate;
import org.springframework.boot.gradle.junit.GradleCompatibility; import org.springframework.boot.gradle.junit.GradleCompatibility;
@ -108,6 +110,13 @@ class BootRunIntegrationTests {
@TestTemplate @TestTemplate
void applicationPluginJvmArgumentsAreUsed() throws IOException { void applicationPluginJvmArgumentsAreUsed() throws IOException {
if (this.gradleBuild.isConfigurationCache()) {
// https://github.com/gradle/gradle/pull/23924
GradleVersion gradleVersion = GradleVersion.version(this.gradleBuild.getGradleVersion());
Assumptions.assumeThat(gradleVersion)
.isLessThan(GradleVersion.version("8.0"))
.isGreaterThanOrEqualTo(GradleVersion.version("8.1-rc-1"));
}
copyJvmArgsApplication(); copyJvmArgsApplication();
BuildResult result = this.gradleBuild.build("bootRun"); BuildResult result = this.gradleBuild.build("bootRun");
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);

@ -0,0 +1,12 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
springBoot {
mainClass = "com.example.Main"
}
gradle.taskGraph.whenReady {
println "developmentOnly exists = ${configurations.findByName('developmentOnly') != null}"
}

@ -3,15 +3,18 @@ plugins {
id 'org.springframework.boot' version '{version}' id 'org.springframework.boot' version '{version}'
} }
springBoot {
mainClass = "com.example.Main"
}
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.compilerArgs = ['-Xlint:all'] options.compilerArgs = ['-Xlint:all']
} }
gradle.taskGraph.whenReady {
task('javaCompileTasksCompilerArgs') { gradle.taskGraph.allTasks.each {
doFirst { if (it instanceof JavaCompile) {
tasks.withType(JavaCompile) { println "${it.name} compiler args: ${it.options.compilerArgs}"
println "${name} compiler args: ${options.compilerArgs}"
} }
} }
} }

@ -3,14 +3,18 @@ plugins {
id 'org.springframework.boot' version '{version}' id 'org.springframework.boot' version '{version}'
} }
springBoot {
mainClass = "com.example.Main"
}
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:all' options.compilerArgs << '-Xlint:all'
} }
task('javaCompileTasksCompilerArgs') { gradle.taskGraph.whenReady {
doFirst { gradle.taskGraph.allTasks.each {
tasks.withType(JavaCompile) { if (it instanceof JavaCompile) {
println "${name} compiler args: ${options.compilerArgs}" println "${it.name} compiler args: ${it.options.compilerArgs}"
} }
} }
} }

@ -3,10 +3,14 @@ plugins {
id 'org.springframework.boot' version '{version}' id 'org.springframework.boot' version '{version}'
} }
task('javaCompileTasksCompilerArgs') { springBoot {
doFirst { mainClass = "com.example.Main"
tasks.withType(JavaCompile) { }
println "${name} compiler args: ${options.compilerArgs}"
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks.each {
if (it instanceof JavaCompile) {
println "${it.name} compiler args: ${it.options.compilerArgs}"
} }
} }
} }

@ -0,0 +1,16 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
springBoot {
mainClass = "com.example.Main"
}
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks.each {
if (it instanceof JavaCompile) {
println "${it.name} = ${it.options.encoding}"
}
}
}

@ -0,0 +1,16 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
springBoot {
mainClass = "com.example.Main"
}
gradle.taskGraph.whenReady {
def attributes = configurations.findByName('productionRuntimeClasspath').attributes
println "${attributes.keySet().size()} productionRuntimeClasspath attributes:"
attributes.keySet().each { attribute ->
println " ${attribute}: ${attributes.getAttribute(attribute)}"
}
}

@ -0,0 +1,19 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
springBoot {
mainClass = "com.example.Main"
}
gradle.taskGraph.whenReady {
analyzeConfiguration('productionRuntimeClasspath')
analyzeConfiguration('runtimeClasspath')
}
def analyzeConfiguration(String configurationName) {
Configuration configuration = configurations.findByName(configurationName)
println "$configurationName canBeResolved: ${configuration.canBeResolved}"
println "$configurationName canBeConsumed: ${configuration.canBeConsumed}"
}

@ -1,49 +0,0 @@
plugins {
id 'org.springframework.boot' version '{version}'
}
if (project.hasProperty('applyJavaPlugin')) {
apply plugin: 'java'
}
task('taskExists') {
doFirst {
println "${taskName} exists = ${tasks.findByName(taskName) != null}"
}
}
task('javaCompileEncoding') {
doFirst {
tasks.withType(JavaCompile) {
println "${name} = ${options.encoding}"
}
}
}
task('configurationExists') {
doFirst {
println "${configurationName} exists = ${configurations.findByName(configurationName) != null}"
}
}
task('configurationAttributes') {
doFirst {
def attributes = configurations.findByName(configurationName).attributes
println "${attributes.keySet().size()} ${configurationName} attributes:"
attributes.keySet().each { attribute ->
println " ${attribute}: ${attributes.getAttribute(attribute)}"
}
}
}
task('configurationResolvabilityAndConsumability') {
if (project.hasProperty("configurationName")) {
Configuration configuration = configurations.findByName(configurationName)
def canBeResolved = configuration.canBeResolved
def canBeConsumed = configuration.canBeConsumed
doFirst {
println "canBeResolved: ${canBeResolved}"
println "canBeConsumed: ${canBeConsumed}"
}
}
}

@ -9,5 +9,5 @@ targetCompatibility = '1.8'
bootBuildImage { bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
pullPolicy = "IF_NOT_PRESENT" pullPolicy = "IF_NOT_PRESENT"
bindings = [ "${projectDir}/bindings/ca-certificates:/platform/bindings/certificates" ] bindings = [ "${projectDir}/bindings/ca-certificates:/platform/bindings/certificates" as String ]
} }

@ -9,5 +9,5 @@ targetCompatibility = '1.8'
bootBuildImage { bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
pullPolicy = "IF_NOT_PRESENT" pullPolicy = "IF_NOT_PRESENT"
buildpacks = [ "file://${projectDir}/buildpack/hello-world" ] buildpacks = [ "file://${projectDir}/buildpack/hello-world" as String ]
} }

@ -9,5 +9,5 @@ targetCompatibility = '1.8'
bootBuildImage { bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
pullPolicy = "IF_NOT_PRESENT" pullPolicy = "IF_NOT_PRESENT"
buildpacks = [ "file://${projectDir}/hello-world.tgz" ] buildpacks = [ "file://${projectDir}/hello-world.tgz" as String ]
} }

@ -7,10 +7,8 @@ bootJar {
mainClass = 'com.example.Application' mainClass = 'com.example.Application'
} }
task resolveResolvableCopyOfUnresolvableConfiguration { gradle.taskGraph.whenReady {
doFirst {
def copy = configurations.implementation.copyRecursive() def copy = configurations.implementation.copyRecursive()
copy.canBeResolved = true copy.canBeResolved = true
copy.resolve() copy.resolve()
}
} }

@ -3,4 +3,6 @@ plugins {
id 'org.springframework.boot' version '{version}' id 'org.springframework.boot' version '{version}'
} }
applicationDefaultJvmArgs = ['-Dcom.foo=bar', '-Dcom.bar=baz'] application {
applicationDefaultJvmArgs = ['-Dcom.foo=bar', '-Dcom.bar=baz']
}

@ -2,9 +2,3 @@ plugins {
id 'application' id 'application'
id 'org.springframework.boot' version '{version}' id 'org.springframework.boot' version '{version}'
} }
bootRun {
doFirst {
println "Main class name = ${bootRun.mainClass.get()}"
}
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,7 +32,7 @@ public final class GradleVersions {
} }
public static List<String> allCompatible() { public static List<String> allCompatible() {
return Arrays.asList("7.5.1", GradleVersion.current().getVersion()); return Arrays.asList("7.5.1", GradleVersion.current().getVersion(), "8.0.1");
} }
public static String minimumCompatible() { public static String minimumCompatible() {

Loading…
Cancel
Save