-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Gradle JDK Automanagement] Install only used JDKs #479
Open
crogoz
wants to merge
31
commits into
develop
Choose a base branch
from
cr/filter-gradle-jdks
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
75a946e
java versions
crogoz 7a71212
default ot false
crogoz 48ec497
.
crogoz 7a57614
Add generated changelog entries
svc-changelog dbc81da
address comments
crogoz 33ab223
readme
crogoz 25ce299
fix
crogoz 2d592ff
wip
crogoz 374e740
option
crogoz 3eabf8c
old gradle-jdks
crogoz 60577fe
libraryTarget first
crogoz d2402de
.
crogoz 72999fe
.
crogoz a79d9e3
Merge branch 'develop' into cr/filter-gradle-jdks
crogoz 2d2bf0e
multiple targets
crogoz 92baa20
tests
crogoz 43d734c
Delete changelog/@unreleased/pr-472.v2.yml
crogoz 2de953a
toolchainflow
crogoz 02dc91e
Merge branch 'cr/filter-gradle-jdks' of github.com:palantir/gradle-jd…
crogoz ad1ccb9
--includeVersion
crogoz 8791e56
.
crogoz 6042ccc
develop version
crogoz b422a7e
Merge branch 'develop' into cr/filter-gradle-jdks
crogoz a82ad63
cleanup
crogoz 7477484
fix
crogoz 6e7e352
better message
crogoz 8c166f6
.
crogoz d22838d
spotless & fix check
crogoz 8c8c5cc
fix
crogoz 1710e98
checks if extra files
crogoz 75c5cdc
.
crogoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,20 @@ | |
|
||
package com.palantir.gradle.jdks; | ||
|
||
import com.palantir.baseline.plugins.javaversions.BaselineJavaVersionExtension; | ||
import com.palantir.baseline.plugins.javaversions.BaselineJavaVersionsExtension; | ||
import com.palantir.baseline.plugins.javaversions.ChosenJavaVersion; | ||
import com.palantir.gradle.jdks.GradleWrapperPatcher.GradleWrapperPatcherTask; | ||
import com.palantir.gradle.jdks.enablement.GradleJdksEnablement; | ||
import com.palantir.gradle.jdks.flow.ToolchainFailureFlowActionsPlugin; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.tasks.TaskProvider; | ||
import org.gradle.api.tasks.wrapper.Wrapper; | ||
import org.gradle.language.base.plugins.LifecycleBasePlugin; | ||
|
@@ -47,6 +53,9 @@ public void apply(Project rootProject) { | |
+ "Gradle version in order to use the JDK setup.", | ||
GradleJdksEnablement.MINIMUM_SUPPORTED_GRADLE_VERSION)); | ||
} | ||
if (areFlowActionsSupported()) { | ||
rootProject.getPluginManager().apply(ToolchainFailureFlowActionsPlugin.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the error message will only be available for repos >= 8.6 |
||
} | ||
rootProject.getPluginManager().apply(LifecycleBasePlugin.class); | ||
rootProject.getPluginManager().apply(PalantirGradleJdksIdeaPlugin.class); | ||
rootProject | ||
|
@@ -58,12 +67,32 @@ public void apply(Project rootProject) { | |
JdksExtension jdksExtension = JdksPlugin.extension(rootProject, jdkDistributions); | ||
|
||
rootProject.getPluginManager().withPlugin("com.palantir.baseline-java-versions", unused -> { | ||
rootProject | ||
.getExtensions() | ||
.getByType(BaselineJavaVersionsExtension.class) | ||
.getSetupJdkToolchains() | ||
.set(false); | ||
BaselineJavaVersionsExtension baselineJavaVersionsExtension = | ||
rootProject.getExtensions().getByType(BaselineJavaVersionsExtension.class); | ||
baselineJavaVersionsExtension.getSetupJdkToolchains().set(false); | ||
|
||
jdksExtension.jdkMajorVersionsToUse().set(rootProject.provider(() -> Stream.of( | ||
jdksExtension.getDaemonTarget(), | ||
baselineJavaVersionsExtension.libraryTarget(), | ||
baselineJavaVersionsExtension.runtime().map(ChosenJavaVersion::javaLanguageVersion), | ||
baselineJavaVersionsExtension | ||
.distributionTarget() | ||
.map(ChosenJavaVersion::javaLanguageVersion)) | ||
.map(Provider::get) | ||
.collect(Collectors.toSet()))); | ||
}); | ||
|
||
rootProject.subprojects( | ||
proj -> proj.getPluginManager().withPlugin("com.palantir.baseline-java-version", unused -> { | ||
BaselineJavaVersionExtension projectVersions = | ||
proj.getExtensions().getByType(BaselineJavaVersionExtension.class); | ||
|
||
jdksExtension.jdkMajorVersionsToUse().addAll(rootProject.provider(() -> Stream.of( | ||
projectVersions.target(), projectVersions.runtime()) | ||
.map(Provider::get) | ||
.map(ChosenJavaVersion::javaLanguageVersion) | ||
.collect(Collectors.toSet()))); | ||
})); | ||
TaskProvider<Wrapper> wrapperTask = rootProject.getTasks().named("wrapper", Wrapper.class); | ||
|
||
TaskProvider<GenerateGradleJdksConfigsTask> generateGradleJdkConfigs = rootProject | ||
|
@@ -89,7 +118,11 @@ public void apply(Project rootProject) { | |
task.getDaemonJavaVersion().set(jdksExtension.getDaemonTarget()); | ||
task.getJavaVersionToJdkDistros() | ||
.putAll(rootProject.provider(() -> JdkDistributionConfigurator.getJavaVersionToJdkDistros( | ||
rootProject, jdkDistributions, jdksExtension))); | ||
rootProject, | ||
jdkDistributions, | ||
jdksExtension, | ||
task.getIncludeAllJdks().get(), | ||
task.getIncludeJavaMajorVersions().get()))); | ||
task.getCaCerts().putAll(jdksExtension.getCaCerts()); | ||
}); | ||
|
||
|
@@ -144,4 +177,8 @@ private static boolean isGradleVersionSupported() { | |
.compareTo(GradleVersion.version(GradleJdksEnablement.MINIMUM_SUPPORTED_GRADLE_VERSION)) | ||
>= 0; | ||
} | ||
|
||
private static boolean areFlowActionsSupported() { | ||
return GradleVersion.current().compareTo(GradleVersion.version("8.6")) >= 0; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...e-jdks/src/main/java/com/palantir/gradle/jdks/flow/ToolchainFailureFlowActionsPlugin.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,54 @@ | ||
/* | ||
* (c) Copyright 2025 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* 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 com.palantir.gradle.jdks.flow; | ||
|
||
import com.palantir.gradle.jdks.GradleJdksConfigsUtils; | ||
import com.palantir.gradle.jdks.enablement.GradleJdksEnablement; | ||
import javax.inject.Inject; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.flow.FlowProviders; | ||
import org.gradle.api.flow.FlowScope; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class ToolchainFailureFlowActionsPlugin implements Plugin<Project> { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ToolchainFailureFlowActionsPlugin.class); | ||
|
||
@Inject | ||
protected abstract FlowScope getFlowScope(); | ||
|
||
@Inject | ||
protected abstract FlowProviders getFlowProviders(); | ||
|
||
@Override | ||
public final void apply(Project project) { | ||
if (!GradleJdksEnablement.isGradleJdkSetupEnabled( | ||
project.getRootProject().getProjectDir().toPath())) { | ||
throw new RuntimeException( | ||
"Cannot apply `ToolchainFailureFlowActionsPlugin` without enabling palantir.jdk.setup.enabled"); | ||
} | ||
getFlowScope().always(ToolchainFlowAction.class, spec -> { | ||
spec.getParameters().getBuildResult().set(getFlowProviders().getBuildWorkResult()); | ||
spec.getParameters() | ||
.getConfiguredJavaMajorVersions() | ||
.set(project.provider(() -> GradleJdksConfigsUtils.getConfiguredJavaMajorVersions( | ||
project.getRootProject().file("gradle/jdks").toPath()))); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to run
./gradlew setupJdks
even with this approach as the user may stop using the old version, and we need to remove itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed, I thought I had the logic in the
check
task to test if there are any extra configuration files in gradle/jdks. I added now that logic in: 1710e98#diff-53f3309ab573fe65d62f8b5bf40e9bb94478d82b4d6434cb6bcf9b25516813a4R134