Skip to content

Change for includeJDK to grab the running JDK #1054

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

Merged
merged 3 commits into from
Apr 25, 2025
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
151 changes: 57 additions & 94 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.gradle.kotlin.dsl.support.zipTo
import org.gradle.internal.jvm.Jvm
import org.gradle.internal.os.OperatingSystem
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
import org.jetbrains.compose.internal.de.undercouch.gradle.tasks.download.Download
import org.jetbrains.kotlin.fir.scopes.impl.overrides
import java.io.FileOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
Expand Down Expand Up @@ -136,11 +136,11 @@ tasks.compileJava{
val version = if(project.version == "unspecified") "1.0.0" else project.version

tasks.register<Exec>("installCreateDmg") {
onlyIf { org.gradle.internal.os.OperatingSystem.current().isMacOsX }
onlyIf { OperatingSystem.current().isMacOsX }
commandLine("arch", "-arm64", "brew", "install", "--quiet", "create-dmg")
}
tasks.register<Exec>("packageCustomDmg"){
onlyIf { org.gradle.internal.os.OperatingSystem.current().isMacOsX }
onlyIf { OperatingSystem.current().isMacOsX }
group = "compose desktop"

val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get()
Expand Down Expand Up @@ -170,8 +170,6 @@ tasks.register<Exec>("packageCustomDmg"){
extra.add("25")
}

commandLine("brew", "install", "--quiet", "create-dmg")

commandLine("create-dmg",
"--volname", packageName,
"--volicon", file("macos/volume.icns"),
Expand All @@ -188,7 +186,7 @@ tasks.register<Exec>("packageCustomDmg"){
}

tasks.register<Exec>("packageCustomMsi"){
onlyIf { org.gradle.internal.os.OperatingSystem.current().isWindows }
onlyIf { OperatingSystem.current().isWindows }
dependsOn("createDistributable")
workingDir = file("windows")
group = "compose desktop"
Expand All @@ -204,20 +202,22 @@ tasks.register<Exec>("packageCustomMsi"){
)
}

val snapname = findProperty("snapname") ?: rootProject.name
val snaparch = when (System.getProperty("os.arch")) {
"amd64", "x86_64" -> "amd64"
"aarch64" -> "arm64"
else -> System.getProperty("os.arch")
}

tasks.register("generateSnapConfiguration"){
onlyIf { org.gradle.internal.os.OperatingSystem.current().isLinux }
val name = findProperty("snapname") ?: rootProject.name
val arch = when (System.getProperty("os.arch")) {
"amd64", "x86_64" -> "amd64"
"aarch64" -> "arm64"
else -> System.getProperty("os.arch")
}

onlyIf { OperatingSystem.current().isLinux }
val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get()
dependsOn(distributable)

val dir = distributable.destinationDir.get()
val content = """
name: $snapname
name: $name
version: $version
base: core22
summary: A creative coding editor
Expand All @@ -244,20 +244,19 @@ tasks.register("generateSnapConfiguration"){
parts:
processing:
plugin: dump
source: deb/processing_$version-1_$snaparch.deb
source: deb/processing_$version-1_$arch.deb
source-type: deb
stage-packages:
- openjdk-17-jre
override-prime: |
snapcraftctl prime
chmod -R +x opt/processing/lib/app/resources/jdk-*
rm -vf usr/lib/jvm/java-17-openjdk-*/lib/security/cacerts
""".trimIndent()
dir.file("../snapcraft.yaml").asFile.writeText(content)
}

tasks.register<Exec>("packageSnap"){
onlyIf { org.gradle.internal.os.OperatingSystem.current().isLinux }
onlyIf { OperatingSystem.current().isLinux }
dependsOn("packageDeb", "generateSnapConfiguration")
group = "compose desktop"

Expand All @@ -279,19 +278,20 @@ tasks.register<Zip>("zipDistributable"){
}

afterEvaluate{
// Override the default DMG task to use our custom one
tasks.named("packageDmg").configure{
dependsOn("packageCustomDmg")
group = "compose desktop"
actions = emptyList()
}

// Override the default MSI task to use our custom one
tasks.named("packageMsi").configure{
dependsOn("packageCustomMsi")
group = "compose desktop"
actions = emptyList()
}
tasks.named("packageDistributionForCurrentOS").configure {
if(org.gradle.internal.os.OperatingSystem.current().isMacOsX
if(OperatingSystem.current().isMacOsX
&& compose.desktop.application.nativeDistributions.macOS.notarization.appleID.isPresent
){
dependsOn("notarizeDmg")
Expand Down Expand Up @@ -322,40 +322,9 @@ tasks.register<Copy>("includeJavaMode") {
into(composeResources("modes/java/mode"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.register<Download>("includeJdk") {
val os = DefaultNativePlatform.getCurrentOperatingSystem()
val arch = when (System.getProperty("os.arch")) {
"amd64", "x86_64" -> "x64"
else -> System.getProperty("os.arch")
}
val platform = when {
os.isWindows -> "windows"
os.isMacOsX -> "mac"
else -> "linux"
}

val javaVersion = System.getProperty("java.version").split(".")[0]
val imageType = "jdk"

src("https://api.adoptium.net/v3/binary/latest/" +
"$javaVersion/ga/" +
"$platform/" +
"$arch/" +
"$imageType/" +
"hotspot/normal/eclipse?project=jdk")

val extension = if (os.isWindows) "zip" else "tar.gz"
val jdk = layout.buildDirectory.file("tmp/jdk-$platform-$arch.$extension")
dest(jdk)
overwrite(false)
doLast {
copy {
val archive = if (os.isWindows) { zipTree(jdk) } else { tarTree(jdk) }
from(archive){ eachFile{ permissions{ unix("755") } } }
into(composeResources(""))
}
}
finalizedBy("prepareAppResources")
tasks.register<Copy>("includeJdk") {
from(Jvm.current().javaHome.absolutePath)
destinationDir = composeResources("jdk").get().asFile
}
tasks.register<Copy>("includeSharedAssets"){
from("../build/shared/")
Expand Down Expand Up @@ -401,6 +370,7 @@ tasks.register<Copy>("includeJavaModeResources") {
from(java.layout.buildDirectory.dir("resources-bundled"))
into(composeResources("../"))
}
// TODO: Move to java mode
tasks.register<Copy>("renameWindres") {
dependsOn("includeSharedAssets","includeJavaModeResources")
val dir = composeResources("modes/java/application/launch4j/bin/")
Expand All @@ -417,29 +387,29 @@ tasks.register<Copy>("renameWindres") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
into(dir)
}
tasks.register("signResources"){
onlyIf {
org.gradle.internal.os.OperatingSystem.current().isMacOsX
&&
compose.desktop.application.nativeDistributions.macOS.signing.sign.get()
}
group = "compose desktop"
tasks.register("includeProcessingResources"){
dependsOn(
"includeJdk",
"includeCore",
"includeJavaMode",
"includeJdk",
"includeSharedAssets",
"includeProcessingExamples",
"includeProcessingWebsiteExamples",
"includeJavaModeResources",
"renameWindres"
)
finalizedBy("prepareAppResources")
finalizedBy("signResources")
}

tasks.register("signResources"){
onlyIf {
OperatingSystem.current().isMacOsX
&&
compose.desktop.application.nativeDistributions.macOS.signing.sign.get()
}
group = "compose desktop"
val resourcesPath = composeResources("")



// find jars in the resources directory
val jars = mutableListOf<File>()
doFirst{
Expand Down Expand Up @@ -472,7 +442,7 @@ tasks.register("signResources"){
include("**/*x86_64*")
include("**/*ffmpeg*")
include("**/ffmpeg*/**")
exclude("jdk-*/**")
exclude("jdk/**")
exclude("*.jar")
exclude("*.so")
exclude("*.dll")
Expand Down Expand Up @@ -508,39 +478,32 @@ tasks.register("signResources"){


}
afterEvaluate {
tasks.named("prepareAppResources").configure {
dependsOn(
"includeCore",
"includeJavaMode",
"includeSharedAssets",
"includeProcessingExamples",
"includeProcessingWebsiteExamples",
"includeJavaModeResources",
"renameWindres"
)
}
tasks.register("setExecutablePermissions") {
description = "Sets executable permissions on binaries in Processing.app resources"
group = "compose desktop"
tasks.register("setExecutablePermissions") {
description = "Sets executable permissions on binaries in Processing.app resources"
group = "compose desktop"

doLast {
val resourcesPath = layout.buildDirectory.dir("compose/binaries")
fileTree(resourcesPath) {
include("**/resources/**/bin/**")
include("**/resources/**/*.sh")
include("**/resources/**/*.dylib")
include("**/resources/**/*.so")
include("**/resources/**/*.exe")
}.forEach { file ->
if (file.isFile) {
file.setExecutable(true, false)
}
doLast {
val resourcesPath = layout.buildDirectory.dir("compose/binaries")
fileTree(resourcesPath) {
include("**/resources/**/bin/**")
include("**/resources/**/lib/**")
include("**/resources/**/*.sh")
include("**/resources/**/*.dylib")
include("**/resources/**/*.so")
include("**/resources/**/*.exe")
}.forEach { file ->
if (file.isFile) {
file.setExecutable(true, false)
}
}
}
}

afterEvaluate {
tasks.named("prepareAppResources").configure {
dependsOn("includeProcessingResources")
}
tasks.named("createDistributable").configure {
dependsOn("signResources", "includeJdk")
finalizedBy("setExecutablePermissions")
}
}
11 changes: 4 additions & 7 deletions app/src/processing/app/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,14 @@ static public File getContentFile(String name) {
static public File getJavaHome() {
var resourcesDir = System.getProperty("compose.application.resources.dir");
if(resourcesDir != null) {
var jdkFolder = Arrays.stream(new File(resourcesDir).listFiles((dir, name) -> dir.isDirectory() && name.startsWith("jdk-")))
.findFirst()
.orElse(null);
if(Platform.isMacOS()){
return new File(jdkFolder, "Contents/Home");
}
var jdkFolder = new File(resourcesDir,"jdk");
if(jdkFolder.exists()){
return jdkFolder;
}
}

var home = System.getProperty("java.home");
if(home != null && new File(home, "bin/java").exists()){
if(home != null){
return new File(home);
}
if (Platform.isMacOS()) {
Expand Down