Skip to content

Commit

Permalink
Merge pull request gradle#25777 Verify support for running on Java 20
Browse files Browse the repository at this point in the history
This contains no actual production changes, as with the Kotlin 1.9.0 upgrade this already works. These are simply test changes to verify that Gradle indeed runs on Java 20.

Fixes gradle#23488

Co-authored-by: Octavia Togami <[email protected]>
  • Loading branch information
bot-gradle and octylFractal committed Jul 24, 2023
2 parents b892fe1 + 6bb99dd commit eedf2e0
Show file tree
Hide file tree
Showing 40 changed files with 339 additions and 142 deletions.
4 changes: 2 additions & 2 deletions .teamcity/src/main/kotlin/common/JvmCategory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum class JvmCategory(
// Oracle doesn't provide zip JDK distribution for Windows anymore, we avoid using it
MIN_VERSION_WINDOWS(JvmVendor.openjdk, JvmVersion.java8),
MAX_LTS_VERSION(JvmVendor.openjdk, JvmVersion.java17),
MAX_VERSION(JvmVendor.openjdk, JvmVersion.java19),
MAX_VERSION(JvmVendor.oracle, JvmVersion.java20),
SANTA_TRACKER_SMOKE_TEST_VERSION(JvmVendor.openjdk, JvmVersion.java17),
EXPERIMENTAL_VERSION(JvmVendor.openjdk, JvmVersion.java19)
EXPERIMENTAL_VERSION(JvmVendor.oracle, JvmVersion.java20)
}
2 changes: 1 addition & 1 deletion .teamcity/src/main/kotlin/common/JvmVendor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package common

enum class JvmVendor(val displayName: String) {
oracle("Oracle"),
openjdk("Openjdk"),
openjdk("Adoptium"),
zulu("Zulu")
}
2 changes: 1 addition & 1 deletion .teamcity/src/main/kotlin/common/JvmVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ enum class JvmVersion(val major: Int) {
java8(8),
java11(11),
java17(17),
java19(19)
java20(20)
}
4 changes: 2 additions & 2 deletions .teamcity/src/test/kotlin/ApplyDefaultConfigurationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class ApplyDefaultConfigurationTest {

private
fun expectedRunnerParam(daemon: String = "--daemon", extraParameters: String = "", os: Os = Os.LINUX): String {
val linuxPaths = "-Porg.gradle.java.installations.paths=%linux.java8.oracle.64bit%,%linux.java11.openjdk.64bit%,%linux.java17.openjdk.64bit%,%linux.java19.openjdk.64bit%,%linux.java8.openjdk.64bit%"
val windowsPaths = "-Porg.gradle.java.installations.paths=%windows.java8.oracle.64bit%,%windows.java11.openjdk.64bit%,%windows.java17.openjdk.64bit%,%windows.java19.openjdk.64bit%,%windows.java8.openjdk.64bit%"
val linuxPaths = "-Porg.gradle.java.installations.paths=%linux.java8.oracle.64bit%,%linux.java11.openjdk.64bit%,%linux.java17.openjdk.64bit%,%linux.java20.openjdk.64bit%,%linux.java8.openjdk.64bit%"
val windowsPaths = "-Porg.gradle.java.installations.paths=%windows.java8.oracle.64bit%,%windows.java11.openjdk.64bit%,%windows.java17.openjdk.64bit%,%windows.java20.openjdk.64bit%,%windows.java8.openjdk.64bit%"
val expectedInstallationPaths = if (os == Os.WINDOWS) windowsPaths else linuxPaths
return "-Dorg.gradle.workers.max=%maxParallelForks% -PmaxParallelForks=%maxParallelForks% $pluginPortalUrlOverride -s --no-configuration-cache %additional.gradle.parameters% $daemon --continue $extraParameters \"-Dscan.tag.Check\" \"-Dscan.tag.\" -PteamCityBuildId=%teamcity.build.id% \"$expectedInstallationPaths\" -Porg.gradle.java.installations.auto-download=false"
}
Expand Down
2 changes: 1 addition & 1 deletion .teamcity/src/test/kotlin/PerformanceTestBuildTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class PerformanceTestBuildTypeTest {
"-PautoDownloadAndroidStudio=true",
"-PrunAndroidStudioInHeadlessMode=true",
"-Porg.gradle.java.installations.auto-download=false",
"\"-Porg.gradle.java.installations.paths=%linux.java8.oracle.64bit%,%linux.java11.openjdk.64bit%,%linux.java17.openjdk.64bit%,%linux.java19.openjdk.64bit%,%linux.java8.openjdk.64bit%\"",
"\"-Porg.gradle.java.installations.paths=%linux.java8.oracle.64bit%,%linux.java11.openjdk.64bit%,%linux.java17.openjdk.64bit%,%linux.java20.openjdk.64bit%,%linux.java8.openjdk.64bit%\"",
"\"-Porg.gradle.performance.branchName=%teamcity.build.branch%\"",
"\"-Porg.gradle.performance.db.url=%performance.db.url%\"",
"\"-Porg.gradle.performance.db.username=%performance.db.username%\"",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* Copyright 2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.buildinit.plugins

import org.gradle.api.JavaVersion
import org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl
import org.gradle.internal.jvm.Jvm
import org.gradle.test.precondition.Requires
import org.gradle.test.preconditions.UnitTestPreconditions

/**
* MavenConversionIntegrationTest tests that use a dynamically-generated POM to ensure cross-version compatibility.
*/
abstract class MavenConversionDynamicPomIntegrationTest extends AbstractInitIntegrationSpec {

@Override
String subprojectName() { null }

abstract BuildInitDsl getScriptDsl()

def setup() {
/**
* We need to configure the local maven repository explicitly as
* RepositorySystem.defaultUserLocalRepository is statically initialised and used when
* creating multiple ProjectBuildingRequest.
* */
m2.generateUserSettingsFile(m2.mavenRepo())
using m2

targetDir.file("src/main/java/Foo.java") << """
import org.apache.commons.lang.StringUtils;
public class Foo {
public String toString() {
return StringUtils.normalizeSpace("hi there!");
}
}
"""
targetDir.file("src/test/java/FooTest.java") << """
import org.junit.Test;
public class FooTest {
@Test public void test() {
assert false: "test failure";
}
}
"""
}

def "singleModule with same source and target"() {
def source = Jvm.current().javaVersion
def target = Jvm.current().javaVersion
writePom(source, target)

def dsl = dslFixtureFor(scriptDsl)

when:
run 'init', '--dsl', scriptDsl.id as String

then:
dsl.assertGradleFilesGenerated()
dsl.getSettingsFile().text.contains("rootProject.name = 'util'") || dsl.getSettingsFile().text.contains('rootProject.name = "util"')
MavenConversionIntegrationTest.assertContainsPublishingConfig(dsl.getBuildFile(), scriptDsl)
dsl.getBuildFile(targetDir).text.contains("java.sourceCompatibility = JavaVersion.${source.name()}")
!dsl.getBuildFile(targetDir).text.contains("java.targetCompatibility = ")

when:
fails 'clean', 'build'

then:
// when tests fail, jar may not exist
failure.assertHasDescription("Execution failed for task ':test'.")
failure.assertHasCause("There were failing tests.")
}

def "singleModule with different source and target"() {
def source = Jvm.current().javaVersion.previous() as JavaVersion
def target = Jvm.current().javaVersion
writePom(source, target)

def dsl = dslFixtureFor(scriptDsl)

when:
run 'init', '--dsl', scriptDsl.id as String

then:
dsl.assertGradleFilesGenerated()
dsl.getSettingsFile().text.contains("rootProject.name = 'util'") || dsl.getSettingsFile().text.contains('rootProject.name = "util"')
MavenConversionIntegrationTest.assertContainsPublishingConfig(dsl.getBuildFile(), scriptDsl)
dsl.getBuildFile(targetDir).text.contains("java.sourceCompatibility = JavaVersion.${source.name()}")
dsl.getBuildFile(targetDir).text.contains("java.targetCompatibility = JavaVersion.${target.name()}")

when:
fails 'clean', 'build'

then:
// when tests fail, jar may not exist
failure.assertHasDescription("Execution failed for task ':test'.")
failure.assertHasCause("There were failing tests.")
}

@Requires(UnitTestPreconditions.Jdk9OrLater)
def "singleModule with just source"() {
def source = Jvm.current().javaVersion
writePom(source, null)

def dsl = dslFixtureFor(scriptDsl)

when:
run 'init', '--dsl', scriptDsl.id as String

then:
dsl.assertGradleFilesGenerated()
dsl.getSettingsFile().text.contains("rootProject.name = 'util'") || dsl.getSettingsFile().text.contains('rootProject.name = "util"')
MavenConversionIntegrationTest.assertContainsPublishingConfig(dsl.getBuildFile(), scriptDsl)
dsl.getBuildFile(targetDir).text.contains("java.sourceCompatibility = JavaVersion.${source.name()}")
// target defaults to 1.8
dsl.getBuildFile(targetDir).text.contains("java.targetCompatibility = JavaVersion.VERSION_1_8")

when:
fails 'clean', 'build'

then:
// if the source and target are different, we can't actually compile because javac requires them to be the same
failure.assertHasDescription("Execution failed for task ':compileJava'.")
// May or may not be part of the failure cause (varies by javac version)
errorOutput.contains("source release ${source} requires target release ${source}")
}

@Requires(UnitTestPreconditions.Jdk9OrLater)
def "singleModule with just target"() {
def target = Jvm.current().javaVersion
writePom(null, target)

def dsl = dslFixtureFor(scriptDsl)

when:
run 'init', '--dsl', scriptDsl.id as String

then:
dsl.assertGradleFilesGenerated()
dsl.getSettingsFile().text.contains("rootProject.name = 'util'") || dsl.getSettingsFile().text.contains('rootProject.name = "util"')
MavenConversionIntegrationTest.assertContainsPublishingConfig(dsl.getBuildFile(), scriptDsl)
// source defaults to 1.8
dsl.getBuildFile(targetDir).text.contains("java.sourceCompatibility = JavaVersion.VERSION_1_8")
dsl.getBuildFile(targetDir).text.contains("java.targetCompatibility = JavaVersion.${target.name()}")

when:
fails 'clean', 'build'

then:
// when tests fail, jar may not exist
failure.assertHasDescription("Execution failed for task ':test'.")
failure.assertHasCause("There were failing tests.")
}

private writePom(source, target) {
// Dynamically generated POM file, based on MavenConversionIntegrationTest#singleModule pom.xml
targetDir.file("pom.xml") << """
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>util</groupId>
<artifactId>util</artifactId>
<version>2.5</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
${source == null ? "" : "<source>${source}</source>"}
${target == null ? "" : "<target>${target}</target>"}
</configuration>
</plugin>
</plugins>
</build>
</project>
"""
}
}

class KotlinDslMavenConversionDynamicPomIntegrationTest extends MavenConversionDynamicPomIntegrationTest {
BuildInitDsl scriptDsl = BuildInitDsl.KOTLIN
}

class GroovyDslMavenConversionDynamicPomIntegrationTest extends MavenConversionDynamicPomIntegrationTest {
BuildInitDsl scriptDsl = BuildInitDsl.GROOVY
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ tasks.withType<Javadoc>() {
}
}

private static void assertContainsPublishingConfig(TestFile buildScript, BuildInitDsl dsl, String indent = "", List<String> additionalArchiveTasks = []) {
static void assertContainsPublishingConfig(TestFile buildScript, BuildInitDsl dsl, String indent = "", List<String> additionalArchiveTasks = []) {
def text = buildScript.text
if (dsl == BuildInitDsl.GROOVY) {
assert text.contains("id 'maven-publish'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source/>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target/>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Loading

0 comments on commit eedf2e0

Please sign in to comment.