Skip to content
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

Use dynamically resolved Java version when creating Gradle projects #37051

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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 @@ -50,13 +50,8 @@ version = "{project.version}"

{#insert java}
java {
{#if java.version == "17"}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
{#else}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
{/if}
sourceCompatibility = JavaVersion.VERSION_{java.version}
targetCompatibility = JavaVersion.VERSION_{java.version}
}
{/}

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

tasks.withType<ScalaCompile> {
scalaCompileOptions.encoding = "UTF-8"
{#if java.version == "11"}
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
{#else}
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
{/if}
sourceCompatibility = JavaVersion.VERSION_{java.version}.toString()
targetCompatibility = JavaVersion.VERSION_{java.version}.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ version '{project.version}'

{#insert java}
java {
{#if java.version == "17"}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
{#else}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
{/if}
sourceCompatibility = JavaVersion.VERSION_{java.version}
targetCompatibility = JavaVersion.VERSION_{java.version}
}
{/}

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

compileScala {
scalaCompileOptions.encoding = 'UTF-8'
{#if java.version == "11"}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
{#else}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
{/if}
sourceCompatibility = JavaVersion.VERSION_{java.version}
targetCompatibility = JavaVersion.VERSION_{java.version}
}
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,24 @@ public void testProjectGenerationFromScratchWithJava17() throws MavenInvocationE
.contains("maven.compiler.release>17<");
}

@Test
public void testProjectGenerationFromScratchWithJava21() throws MavenInvocationException, IOException {
testDir = initEmptyProject("projects/project-generation-with-java21");
assertThat(testDir).isDirectory();
invoker = initInvoker(testDir);

Properties properties = new Properties();
properties.put("javaVersion", "21");

InvocationResult result = setup(properties);
assertThat(result.getExitCode()).isZero();

testDir = new File(testDir, "code-with-quarkus");
assertThat(new File(testDir, "pom.xml")).isFile();
assertThat(FileUtils.readFileToString(new File(testDir, "pom.xml"), "UTF-8"))
.contains("maven.compiler.release>21<");
}

@Test
public void testProjectGenerationFromScratchWithGradleJava11() throws MavenInvocationException, IOException {
testDir = initEmptyProject("projects/project-generation-with-gradle-java11");
Expand Down Expand Up @@ -532,6 +550,25 @@ public void testProjectGenerationFromScratchWithGradleJava17() throws MavenInvoc
.contains("sourceCompatibility = JavaVersion.VERSION_17");
}

@Test
public void testProjectGenerationFromScratchWithGradleJava21() throws MavenInvocationException, IOException {
testDir = initEmptyProject("projects/project-generation-with-gradle-java21");
assertThat(testDir).isDirectory();
invoker = initInvoker(testDir);

Properties properties = new Properties();
properties.put("javaVersion", "21");
properties.put("buildTool", "gradle");

InvocationResult result = setup(properties);
assertThat(result.getExitCode()).isZero();

testDir = new File(testDir, "code-with-quarkus");
assertThat(new File(testDir, "build.gradle")).isFile();
assertThat(FileUtils.readFileToString(new File(testDir, "build.gradle"), "UTF-8"))
.contains("sourceCompatibility = JavaVersion.VERSION_21");
}

/**
* Reproducer for https://github.com/quarkusio/quarkus/issues/671
*/
Expand Down
Loading