Skip to content

Increase test coverage on Java 16 #25809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.GradleBuild;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.api.tasks.testing.Test;
Expand Down Expand Up @@ -57,8 +56,8 @@ private void configure(Project project, ToolchainExtension toolchain) {
JavaToolchainSpec toolchainSpec = project.getExtensions().getByType(JavaPluginExtension.class)
.getToolchain();
toolchainSpec.getLanguageVersion().set(toolchain.getJavaVersion());
configureJavaCompileToolchain(project, toolchain);
configureTestToolchain(project, toolchain);
configureJavaCompileToolchain(project);
configureTestToolchain(project);
}
}

Expand All @@ -71,10 +70,9 @@ private void disableToolchainTasks(Project project) {
project.getTasks().withType(JavaCompile.class, (task) -> task.setEnabled(false));
project.getTasks().withType(Javadoc.class, (task) -> task.setEnabled(false));
project.getTasks().withType(Test.class, (task) -> task.setEnabled(false));
project.getTasks().withType(GradleBuild.class, (task) -> task.setEnabled(false));
}

private void configureJavaCompileToolchain(Project project, ToolchainExtension toolchain) {
private void configureJavaCompileToolchain(Project project) {
project.getTasks().withType(JavaCompile.class, (compile) -> {
compile.getOptions().setFork(true);
// See https://github.com/gradle/gradle/issues/15538
Expand All @@ -83,7 +81,7 @@ private void configureJavaCompileToolchain(Project project, ToolchainExtension t
});
}

private void configureTestToolchain(Project project, ToolchainExtension toolchain) {
private void configureTestToolchain(Project project) {
project.getTasks().withType(Test.class, (test) -> {
// See https://github.com/spring-projects/spring-ldap/issues/570
List<String> arguments = Arrays.asList("--add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ plugins {

description = "Spring Boot Gradle Plugin"

toolchain {
maximumCompatibleJavaVersion = JavaLanguageVersion.of(15)
}

configurations {
documentation
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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 @@ -19,6 +19,8 @@
import java.io.IOException;

import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
Expand All @@ -37,6 +39,7 @@ class PublishingDocumentationTests {

GradleBuild gradleBuild;

@DisabledForJreRange(min = JRE.JAVA_16)
@TestTemplate
void mavenUpload() throws IOException {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("5.6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.stream.Stream;

import org.gradle.api.JavaVersion;
import org.gradle.util.GradleVersion;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.Extension;
Expand All @@ -42,8 +43,17 @@
*/
final class GradleCompatibilityExtension implements TestTemplateInvocationContextProvider {

private static final List<String> GRADLE_VERSIONS = Arrays.asList("6.3", "6.4.1", "6.5.1", "6.6.1", "6.7.1",
"current", "7.0-rc-1");
private static final List<String> GRADLE_VERSIONS;

static {
JavaVersion javaVersion = JavaVersion.current();
if (javaVersion.isCompatibleWith(JavaVersion.VERSION_16)) {
GRADLE_VERSIONS = Arrays.asList("7.0-rc-1");
}
else {
GRADLE_VERSIONS = Arrays.asList("6.3", "6.4.1", "6.5.1", "6.6.1", "6.7.1", "current", "7.0-rc-1");
}
}

@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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 @@ -20,6 +20,7 @@
import java.util.List;
import java.util.stream.Stream;

import org.gradle.api.JavaVersion;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand Down Expand Up @@ -59,7 +60,12 @@ private static final class DslTestTemplateInvocationContext implements TestTempl

@Override
public List<Extension> getAdditionalExtensions() {
return Arrays.asList(new GradleBuildFieldSetter(new GradleBuild(this.dsl)), new GradleBuildExtension());
GradleBuild gradleBuild = new GradleBuild(this.dsl);
JavaVersion javaVersion = JavaVersion.current();
if (javaVersion.isCompatibleWith(JavaVersion.VERSION_16)) {
gradleBuild.gradleVersion("7.0-rc-1");
}
return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.springframework.boot.gradle.plugin;

import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

import org.springframework.boot.gradle.junit.GradleCompatibility;
import org.springframework.boot.gradle.testkit.GradleBuild;
Expand All @@ -28,6 +30,7 @@
*
* @author Andy Wilkinson
*/
@DisabledForJreRange(min = JRE.JAVA_16)
@GradleCompatibility(versionsLessThan = "7.0-milestone-1")
class MavenPluginActionIntegrationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void failFastWithVersionOfGradle6LowerThanRequired() {
.contains("Spring Boot plugin requires Gradle 6 (6.3 or later). The current version is Gradle 6.2.2");
}

@DisabledForJreRange(min = JRE.JAVA_16)
@Test
void succeedWithVersionOfGradle6MatchingWithIsRequired() {
this.gradleBuild.gradleVersion("6.3").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

import org.springframework.boot.gradle.junit.GradleCompatibility;
import org.springframework.boot.gradle.testkit.GradleBuild;
Expand All @@ -34,6 +36,7 @@
*
* @author Andy Wilkinson
*/
@DisabledForJreRange(min = JRE.JAVA_16)
@GradleCompatibility(versionsLessThan = "7.0-milestone-1")
class MavenIntegrationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ plugins {

description = "Spring Boot Launch Script Integration Tests"

toolchain {
maximumCompatibleJavaVersion = JavaLanguageVersion.of(15)
}

configurations {
app
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ plugins {

description = "Spring Boot Loader Integration Tests"

toolchain {
maximumCompatibleJavaVersion = JavaLanguageVersion.of(15)
}

configurations {
app
}
Expand Down