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

Set JAVA_HOME in gradle-jdks-setup script #447

Merged
merged 14 commits into from
Oct 25, 2024
Merged

Conversation

crogoz
Copy link
Contributor

@crogoz crogoz commented Oct 24, 2024

Before this PR

In case there is no JAVA_HOME, then ./gradlew will look at java executable (https://github.com/palantir/gradle-jdks/blob/develop/gradlew#L142). If no java is installed, then the ./gradlew command will fail.

example: https://app.circleci.com/pipelines/github/palantir/gradle-jdks/2274/workflows/66d6abd4-88f9-4525-aed9-e91363f1921a/jobs/6532 when trying to drop the "Install Java" step from the circle-ci template (369952b#diff-78a8a19706dbd2a4425dd72bdab0502ed7a2cef16365ab7030a5a0588927bf47L93-L98)

After this PR

Gradle JDK Automanagement will also set JAVA_HOME used by ./gradlew to launch Gradle (https://github.com/palantir/gradle-jdks/blob/develop/gradlew#L128-L150).

==COMMIT_MSG==
gradle-jdks-setup.sh script sets JAVA_HOME to gradle JDK
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Oct 24, 2024

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

gradle-jdks-setup.sh script sets JAVA_HOME to gradle JDK

Check the box to generate changelog(s)

  • Generate changelog entry

@crogoz crogoz changed the title Cr/java home Set JAVA_HOME in gradle-jdks-setup script Oct 24, 2024
Comment on lines -138 to -147
caResources
.readPalantirRootCaFromSystemTruststore()
.map(AliasContentCert::getContent)
.ifPresent(content -> {
try {
Files.write(workingDir.resolve("palantir.crt"), content.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("Failed to write cert", e);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need this as we just read certs from the system truststore right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Comment on lines 8 to 18
# >>> Gradle JDK setup >>>
# !! Contents within this block are managed by 'palantir/gradle-jdks' !!
if [ -f gradle/gradle-jdks-setup.sh ]; then
if ! . gradle/gradle-jdks-setup.sh; then
echo "Failed to set up JDK, running gradle/gradle-jdks-setup.sh failed with non-zero exit code"
exit 1
fi
# Setting JAVA_HOME to the gradle daemon to make sure gradlew uses this jdk for `JAVACMD`
JAVA_HOME="$GRADLE_DAEMON_JDK"
fi
echo "Example.com cert:" $(/root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1/bin/keytool -keystore /root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1/lib/security/cacerts -list -alias gradleJdks_example.com -storepass changeit)
# <<< Gradle JDK setup <<<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this manually placed here or is it kept up to date with gradlew-patch.sh somehow?

@@ -42,7 +42,7 @@ tasks.integrationTest {
dependsOn tasks.fatJar
}

tasks.build.dependsOn tasks.fatJar
tasks.build.dependsOn tasks.fatJar, tasks.integrationTest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the integration tests were not running before :(

@@ -74,6 +74,7 @@ gradle_daemon_jdk_distribution_local_path=$(read_value "$APP_GRADLE_DIR"/jdks/"$
"$GRADLE_JDKS_HOME"/"$gradle_daemon_jdk_distribution_local_path"/bin/java -cp "$APP_GRADLE_DIR"/gradle-jdks-setup.jar com.palantir.gradle.jdks.setup.GradleJdkInstallationSetup daemonSetup "$APP_HOME" "$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path"

# [Used by ./gradlew only] Setting the Gradle Daemon Java Home to the JDK distribution
set -- "-Dorg.gradle.java.home=$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path" "$@"
export GRADLE_DAEMON_JDK="$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not setting the JAVA_HOME directly here as this script is called by the palantir-gradle-jdks intellij plugin as well and I don't think we should modify the JAVA_HOME there (when gradle jdk automanagement is set, then we also set the Project SDK)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am I right in thinking setting JAVA_HOME wouldn't really do anything bad though? We'd set the JAVA_HOME then the script would end to no real effect (when called from intellij in the before gradle step right?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I think it really matters, the export GRADLE_DAEMON_JDK approach here is also fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am I right in thinking setting JAVA_HOME wouldn't really do anything bad though? We'd set the JAVA_HOME then the script would end to no real effect (when called from intellij in the before gradle step right?

I think you are right (I tested this initially inside Intellij) and it seemed fine. But I wouldn't want to add to any confusion if in the end something inside Intellij changes and the java home is somehow used.

@crogoz crogoz requested a review from CRogers October 25, 2024 09:59
@CRogers CRogers closed this Oct 25, 2024
@CRogers CRogers reopened this Oct 25, 2024
@bulldozer-bot bulldozer-bot bot merged commit 2447cc1 into develop Oct 25, 2024
6 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cr/java-home branch October 25, 2024 16:39
@autorelease3
Copy link

autorelease3 bot commented Oct 25, 2024

Released 0.52.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants