-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for Java Toolchains in Quarkus Gradle plugin
Closes #20452
- Loading branch information
Showing
13 changed files
with
281 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...le/gradle-application-plugin/src/test/java/io/quarkus/gradle/tasks/JavaToolchainTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.quarkus.gradle.tasks; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
|
||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
|
||
public class JavaToolchainTest { | ||
|
||
@TempDir | ||
Path testProjectDir; | ||
|
||
@Test | ||
void quarkusIsUsingJavaToolchain() throws Exception { | ||
URL url = getClass().getClassLoader().getResource("io/quarkus/gradle/tasks/toolchain/main"); | ||
FileUtils.copyDirectory(new File(url.toURI()), testProjectDir.toFile()); | ||
FileUtils.copyFile(new File("../gradle.properties"), testProjectDir.resolve("gradle.properties").toFile()); | ||
|
||
GradleRunner.create() | ||
.withPluginClasspath() | ||
.withProjectDir(testProjectDir.toFile()) | ||
.withArguments("build", "--info", "--stacktrace", "--build-cache", "--configuration-cache") | ||
// .build() checks whether the build failed, which is good enough for this test | ||
.build(); | ||
} | ||
|
||
@Test | ||
void quarkusPluginCanOverrideJavaToolchain() throws Exception { | ||
URL url = getClass().getClassLoader().getResource("io/quarkus/gradle/tasks/toolchain/custom"); | ||
FileUtils.copyDirectory(new File(url.toURI()), testProjectDir.toFile()); | ||
FileUtils.copyFile(new File("../gradle.properties"), testProjectDir.resolve("gradle.properties").toFile()); | ||
|
||
GradleRunner.create() | ||
.withPluginClasspath() | ||
.withProjectDir(testProjectDir.toFile()) | ||
.withArguments("build", "--info", "--stacktrace", "--build-cache", "--configuration-cache") | ||
// .build() checks whether the build failed, which is good enough for this test | ||
.build(); | ||
} | ||
|
||
@Test | ||
void quarkusPluginFailsWithIncompatibleToolchains() throws Exception { | ||
URL url = getClass().getClassLoader().getResource("io/quarkus/gradle/tasks/toolchain/fail"); | ||
FileUtils.copyDirectory(new File(url.toURI()), testProjectDir.toFile()); | ||
FileUtils.copyFile(new File("../gradle.properties"), testProjectDir.resolve("gradle.properties").toFile()); | ||
|
||
BuildResult buildResult = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withProjectDir(testProjectDir.toFile()) | ||
.withArguments("build", "--info", "--stacktrace", "--build-cache", "--configuration-cache") | ||
.buildAndFail(); | ||
|
||
assertThat(buildResult.task(":quarkusAppPartsBuild").getOutcome()).isEqualTo(TaskOutcome.FAILED); | ||
assertThat(buildResult.getOutput()).contains("java.lang.UnsupportedClassVersionError"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ation-plugin/src/test/resources/io/quarkus/gradle/tasks/toolchain/custom/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
plugins { | ||
java | ||
id("io.quarkus") | ||
} | ||
|
||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(enforcedPlatform("io.quarkus:quarkus-bom:${project.property("version")}")) | ||
implementation("io.quarkus:quarkus-core") | ||
implementation("jakarta.inject:jakarta.inject-api:2.0.1") | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
tasks.withType(io.quarkus.gradle.tasks.QuarkusTask::class.java) { | ||
javaLauncher = javaToolchains.launcherFor { | ||
languageVersion = JavaLanguageVersion.of(21) | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...on-plugin/src/test/resources/io/quarkus/gradle/tasks/toolchain/custom/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
plugins { | ||
id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") | ||
} | ||
|
||
rootProject.name = "gradle-java-toolchain" |
8 changes: 8 additions & 0 deletions
8
...c/test/resources/io/quarkus/gradle/tasks/toolchain/custom/src/main/java/org/acme/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.acme; | ||
|
||
import io.smallrye.config.ConfigMapping; | ||
|
||
@ConfigMapping(prefix = "foo") | ||
public interface Foo { | ||
String string(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...ication-plugin/src/test/resources/io/quarkus/gradle/tasks/toolchain/fail/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
plugins { | ||
java | ||
id("io.quarkus") | ||
} | ||
|
||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(enforcedPlatform("io.quarkus:quarkus-bom:${project.property("version")}")) | ||
implementation("io.quarkus:quarkus-core") | ||
implementation("jakarta.inject:jakarta.inject-api:2.0.1") | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(21) | ||
} | ||
} | ||
|
||
tasks.withType(io.quarkus.gradle.tasks.QuarkusTask::class.java) { | ||
javaLauncher = javaToolchains.launcherFor { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...tion-plugin/src/test/resources/io/quarkus/gradle/tasks/toolchain/fail/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
plugins { | ||
id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") | ||
} | ||
|
||
rootProject.name = "gradle-java-toolchain" |
8 changes: 8 additions & 0 deletions
8
...src/test/resources/io/quarkus/gradle/tasks/toolchain/fail/src/main/java/org/acme/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.acme; | ||
|
||
import io.smallrye.config.ConfigMapping; | ||
|
||
@ConfigMapping(prefix = "foo") | ||
public interface Foo { | ||
String string(); | ||
} |
Oops, something went wrong.