Skip to content

Commit

Permalink
Merge branch '2.7.x' into 3.0.x
Browse files Browse the repository at this point in the history
Closes gh-34460
  • Loading branch information
wilkinsona committed Mar 3, 2023
2 parents f5a8a71 + 4f7e038 commit 03dd666
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@ protected BootRunClasspathApplication() {
}

public static void main(String[] args) {
System.out.println("Main class name = " + BootRunClasspathApplication.class.getName());
int i = 1;
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator)) {
System.out.println(i++ + ". " + entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,53 +47,46 @@ class JavaPluginActionIntegrationTests {

@TestTemplate
void noBootJarTaskWithoutJavaPluginApplied() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar").getOutput())
.contains("bootJar exists = false");
assertThat(this.gradleBuild.build("tasks").getOutput()).doesNotContain("bootJar");
}

@TestTemplate
void applyingJavaPluginCreatesBootJarTask() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin").getOutput())
.contains("bootJar exists = true");
assertThat(this.gradleBuild.build("tasks").getOutput()).contains("bootJar");
}

@TestTemplate
void noBootRunTaskWithoutJavaPluginApplied() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun").getOutput())
.contains("bootRun exists = false");
assertThat(this.gradleBuild.build("tasks").getOutput()).doesNotContain("bootRun");
}

@TestTemplate
void applyingJavaPluginCreatesBootRunTask() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin").getOutput())
.contains("bootRun exists = true");
assertThat(this.gradleBuild.build("tasks").getOutput()).contains("bootRun");
}

@TestTemplate
void javaCompileTasksUseUtf8Encoding() {
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin").getOutput())
.contains("compileJava = UTF-8")
assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava = UTF-8")
.contains("compileTestJava = UTF-8");
}

@TestTemplate
void javaCompileTasksUseParametersCompilerFlagByDefault() {
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
.contains("compileJava compiler args: [-parameters]")
assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava compiler args: [-parameters]")
.contains("compileTestJava compiler args: [-parameters]");
}

@TestTemplate
void javaCompileTasksUseParametersAndAdditionalCompilerFlags() {
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
assertThat(this.gradleBuild.build("build").getOutput())
.contains("compileJava compiler args: [-parameters, -Xlint:all]")
.contains("compileTestJava compiler args: [-parameters, -Xlint:all]");
}

@TestTemplate
void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() {
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
.contains("compileJava compiler args: [-Xlint:all]")
assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava compiler args: [-Xlint:all]")
.contains("compileTestJava compiler args: [-Xlint:all]");
}

Expand Down Expand Up @@ -139,35 +132,24 @@ void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent() throws IOEx

@TestTemplate
void applyingJavaPluginCreatesDevelopmentOnlyConfiguration() {
assertThat(this.gradleBuild
.build("configurationExists", "-PconfigurationName=developmentOnly", "-PapplyJavaPlugin")
.getOutput()).contains("developmentOnly exists = true");
assertThat(this.gradleBuild.build("build").getOutput()).contains("developmentOnly exists = true");
}

@TestTemplate
void productionRuntimeClasspathIsConfiguredWithAttributes() {
assertThat(this.gradleBuild
.build("configurationAttributes", "-PconfigurationName=productionRuntimeClasspath", "-PapplyJavaPlugin")
.getOutput()).contains("3 productionRuntimeClasspath attributes:")
assertThat(this.gradleBuild.build("build").getOutput()).contains("3 productionRuntimeClasspath attributes:")
.contains("org.gradle.usage: java-runtime")
.contains("org.gradle.libraryelements: jar")
.contains("org.gradle.dependency.bundling: external");
}

@TestTemplate
void productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath() {
String runtime = this.gradleBuild
.build("configurationResolvabilityAndConsumability", "-PconfigurationName=runtimeClasspath",
"-PapplyJavaPlugin")
.getOutput();
assertThat(runtime).contains("canBeResolved: true");
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");
String output = this.gradleBuild.build("build").getOutput();
assertThat(output).contains("runtimeClasspath canBeResolved: true");
assertThat(output).contains("runtimeClasspath canBeConsumed: false");
assertThat(output).contains("productionRuntimeClasspath canBeResolved: true");
assertThat(output).contains("productionRuntimeClasspath canBeConsumed: false");
}

@TestTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.TreeSet;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.TestTemplate;

import org.springframework.boot.gradle.junit.GradleCompatibility;
Expand All @@ -45,9 +44,7 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {

@TestTemplate
void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() {
BuildResult build = this.gradleBuild.build("resolveResolvableCopyOfUnresolvableConfiguration");
assertThat(build.task(":resolveResolvableCopyOfUnresolvableConfiguration").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("8.0").build("build");
}

@TestTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand All @@ -16,10 +16,14 @@

package org.springframework.boot.gradle.tasks.bundling;

import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;

import org.assertj.core.api.Assumptions;
import org.gradle.util.GradleVersion;

import org.springframework.boot.gradle.junit.GradleCompatibility;

/**
Expand All @@ -42,4 +46,25 @@ String[] getExpectedApplicationLayerContents(String... additionalFiles) {
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"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;

import org.assertj.core.api.Assumptions;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.gradle.util.GradleVersion;
import org.junit.jupiter.api.TestTemplate;

import org.springframework.boot.gradle.junit.GradleCompatibility;
Expand Down Expand Up @@ -108,6 +110,13 @@ void optimizedLaunchDisabledJvmArgs() throws IOException {

@TestTemplate
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();
BuildResult result = this.gradleBuild.build("bootRun");
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
Original file line number Diff line number Diff line change
@@ -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}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ plugins {
id 'org.springframework.boot' version '{version}'
}

springBoot {
mainClass = "com.example.Main"
}

tasks.withType(JavaCompile) {
options.compilerArgs = ['-Xlint:all']
}


task('javaCompileTasksCompilerArgs') {
doFirst {
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}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ plugins {
id 'org.springframework.boot' version '{version}'
}

springBoot {
mainClass = "com.example.Main"
}

tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:all'
}

task('javaCompileTasksCompilerArgs') {
doFirst {
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}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ plugins {
id 'org.springframework.boot' version '{version}'
}

task('javaCompileTasksCompilerArgs') {
doFirst {
tasks.withType(JavaCompile) {
println "${name} compiler args: ${options.compilerArgs}"
springBoot {
mainClass = "com.example.Main"
}

gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks.each {
if (it instanceof JavaCompile) {
println "${it.name} compiler args: ${it.options.compilerArgs}"
}
}
}
Original file line number Diff line number Diff line change
@@ -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}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'org.springframework.boot' version '{version}'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'org.springframework.boot' version '{version}'
}
Original file line number Diff line number Diff line change
@@ -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)}"
}
}
Original file line number Diff line number Diff line change
@@ -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}"
}
Loading

0 comments on commit 03dd666

Please sign in to comment.