feat: detect project's openjdk version#169
Merged
vpa1977 merged 28 commits intorockcrafters:mainfrom Dec 2, 2025
Merged
Conversation
Toolchain.getToolchainVersion will return the toolchain configuration for the current project. If the toolchain settings can not be read, it will return openjdk-21.
- add final modifier - remove unused imports
- we lack openjdk-25 slices in the official release.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds automatic detection of the project's OpenJDK version from the configured Java toolchain. Instead of defaulting to openjdk-21-jdk, the build tools now inspect the Maven/Gradle toolchain configuration to determine the appropriate JDK package.
Key changes:
- Introduced
ToolchainHelperutility to parsejavac -versionoutput and map versions to OpenJDK packages - Added toolchain detection in both Maven and Gradle plugins via new
Toolchainclasses - Modified default
buildPackagefrom hardcodedopenjdk-21-jdkto empty string, triggering automatic detection - Added comprehensive test coverage for toolchain version detection (Java 8, 11, 17)
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| ToolchainHelper.java | Core utility for detecting JDK version from javac executable |
| Toolchain.java (maven) | Maven-specific toolchain detection using ToolchainManager |
| Toolchain.java (gradle) | Gradle-specific toolchain detection using JavaToolchainService |
| CommonRockcraftOptions.java | Changed default buildPackage from "openjdk-21-jdk" to "" |
| BuildRockcraftOptions.java | Removed hardcoded openjdk-21-jdk-headless default |
| CreateBuildRockMojo.java | Added toolchain detection when buildPackage is empty |
| AbstractRockMojo.java | Added toolchain detection when buildPackage is empty |
| CreateRockcraftTask.java | Added toolchain detection when buildPackage is empty |
| CreateBuildRockcraftTask.java | Added toolchain detection and JavaToolchainService injection |
| AbstractRockcraftTask.java | Changed to abstract class with JavaToolchainService injection |
| BuildRockcraftTask.java | Changed to abstract class for toolchain service injection |
| PushRockcraftTask.java | Changed to abstract class for toolchain service injection |
| ToolchainTest.java | Unit tests for Maven toolchain detection logic |
| CreateBuildRockTest.java | Integration test for Gradle toolchain detection |
| RawRunimePartTest.java | Updated test to set buildPackage explicitly |
| pom.xml | Updated Mockito version and added mockito-core/junit-jupiter dependencies |
| toolchain-test/* | Integration test resources for Maven toolchain verification |
| toolchain-options.in | Test fixture for Gradle toolchain configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rockcraft/src/test/java/com/canonical/rockcraft/builder/RawRuntimePartTest.java
Show resolved
Hide resolved
rockcraft/src/main/java/com/canonical/rockcraft/util/ToolchainHelper.java
Outdated
Show resolved
Hide resolved
rockcraft/src/main/java/com/canonical/rockcraft/util/ToolchainHelper.java
Outdated
Show resolved
Hide resolved
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/Toolchain.java
Outdated
Show resolved
Hide resolved
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/Toolchain.java
Outdated
Show resolved
Hide resolved
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/Toolchain.java
Outdated
Show resolved
Hide resolved
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/Toolchain.java
Outdated
Show resolved
Hide resolved
Mockito 5.x requires 11+. Use --release 8 in the pom.xml to produce Java 8 compatible classes. Use Java 21 for building.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Vladimir Petko <vladimir.petko@canonical.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Vladimir Petko <vladimir.petko@canonical.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Vladimir Petko <vladimir.petko@canonical.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Vladimir Petko <vladimir.petko@canonical.com>
Toolchain unit tests try to run Java 8 and Java 11 javac.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rockcraft/src/main/java/com/canonical/rockcraft/util/ToolchainHelper.java
Outdated
Show resolved
Hide resolved
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/PushRockcraftTask.java
Outdated
Show resolved
Hide resolved
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/BuildRockcraftTask.java
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Vladimir Petko <vladimir.petko@canonical.com>
Pulled toolchain service down since only Create(Build)Rock tasks need it.
- specify openjdk discovery configuration - require openjdk range
pushkarnk
reviewed
Dec 2, 2025
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/AbstractRockcraftTask.java
Outdated
Show resolved
Hide resolved
pushkarnk
approved these changes
Dec 2, 2025
# Conflicts: # .github/workflows/build.yml
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes:
update maven project to use build JDK 21 and use --release 8
Add Toolchain helpers to read Maven and Gradle toolchain settings. If not configured, use current Java. Default to OpenJDK 21 if OpenJDK supported by chisel is not found (8,11,17 and 21).
Add unit and integration tests.
Have you signed the CLA?