From a4b36c463c51648ef5484dcd4ef1f81dba21aef5 Mon Sep 17 00:00:00 2001 From: alkum Date: Fri, 8 Apr 2022 23:08:09 +0200 Subject: [PATCH 1/2] Add initial version of building binary Add shadow jar and jpackager plugins that allow the building of platform-specific binaries and installers. --- desktopapp/build.gradle | 89 +++++++++++++++++++++++++++++++++++++++ docs/dev-gradle.md | 18 +++++++- gradle/libs.versions.toml | 6 ++- 3 files changed, 111 insertions(+), 2 deletions(-) diff --git a/desktopapp/build.gradle b/desktopapp/build.gradle index 8d4db5c024..3c78a744b5 100644 --- a/desktopapp/build.gradle +++ b/desktopapp/build.gradle @@ -3,6 +3,8 @@ plugins { id 'application' /* id 'distribution'*/ //todo as long we dont need a jar we leave that out, speeds up build alias(libs.plugins.openjfx) + alias(libs.plugins.jpackage) + alias(libs.plugins.shadow) } apply from: '../buildSrc/bisq-version.gradle' @@ -76,3 +78,90 @@ dependencies { implementation 'org.fxmisc.richtext:richtextfx:0.10.9' } + +distZip.enabled = false +distTar.enabled = false +shadowDistZip.enabled = false +shadowDistTar.enabled = false + +tasks.jpackage { + dependsOn rootProject.clean + dependsOn tasks.build, tasks.shadowJar + + appName = "Bisq 2" + // Remove the -SNAPSHOT suffix from the version string (originally defined in build.gradle) + // Having it in would have resulted in an invalid version property for several platforms (mac, linux/rpm) + appVersion = version.replaceAll("-SNAPSHOT", "") + copyright = 'Copyright (c) 2013-2022 The Bisq developers' + appDescription = 'A decentralized bitcoin exchange network.' + vendor = 'Bisq' + mainClass = "bisq.desktopapp.Main" + mainJar = jar.archiveFileName.get() + verbose = true +// arguments = --arguments
+ destination = "$buildDir/$distsDirName" + input = "$buildDir/$libsDirName" + licenseFile = "../LICENSE" +// resourceDir = --resource-dir // TODO + runtimeImage = System.getProperty("java.home") +// launchers = --add-launcher = // TODO add multiple launchers? desktopapp / satoshiapp + + winMenu = true + winDirChooser = true +// winUpgradeUuid = win-upgrade-uuid // TODO +// winMenuGroup = --win-menu-group // TODO + winShortcut = true + winPerUserInstall = true + winConsole = false + +// macPackageIdentifier = --mac-package-identifier // TODO +// macPackageName = --mac-package-name // TODO +// macPackageSigningPrefix = --mac-package-signing-prefix // TODO + macSign = false +// macSigningKeychain = --mac-signing-keychain // TODO +// macSigningKeyUserName = --mac-signing-key-user-name // TODO + + linuxPackageName = 'bisq2' + linuxDebMaintainer = 'noreply@bisq.network' + linuxMenuGroup = 'Network' + linuxRpmLicenseType = 'AGPLv3' // https://fedoraproject.org/wiki/Licensing:Main?rd=Licensing#Good_Licenses + // This represents the linux package version (revision) + // By convention, this is part of the deb/rpm package names, in addition to the software version + linuxAppRelease = '1' +// linuxAppCategory = --linux-app-category // TODO + linuxShortcut = true + + mac { + // Avoid error "The first number in an app-version cannot be zero or negative." + appVersion = appVersion.startsWith('0') ? '1.0.0' : appVersion +// icon = "icons/icons.icns" // TODO + } + + linux { + // Had issues when using package-manager-installed-jdk + // Worked well when using IntelliJ IDEA SDKs (File > Project Structure > SDKs > + sign > Download JDK + runtimeImage = "/home/user/.jdks/openjdk-17.0.2" +// icon = "icons/icons.ico" // TODO + } + + additionalParameters = ['--verbose'] + + // TODO Choose sane defaults + javaOptions = [ + '-Dfile.encoding=UTF-8', + '-Dbisq.application.appName=bisq_Alice', + '-Dbisq.networkServiceConfig.supportedTransportTypes.0=CLEAR', + '-Dbisq.networkServiceConfig.seedAddressByTransportType.clear.0=127.0.0.1:8000', + '-Dbisq.networkServiceConfig.seedAddressByTransportType.clear.1=127.0.0.1:8001' + ] + + doLast() { + File binariesFolderPath = new File("$buildDir/$distsDirName") + ant.checksum(algorithm: 'SHA-256') { + ant.fileset(dir: "${binariesFolderPath}") + } + println "The binaries and checksums are ready:" + FileCollection collection = layout.files { binariesFolderPath.listFiles() } + collection.collect { it.path }.sort().each { println it } + } +} \ No newline at end of file diff --git a/docs/dev-gradle.md b/docs/dev-gradle.md index 2c04b66d84..8a8e88cc2a 100644 --- a/docs/dev-gradle.md +++ b/docs/dev-gradle.md @@ -56,9 +56,25 @@ To summarize: direct and transitive. +## Package binaries + +Platform-specific binaries and installers can be generated with + +``` +./gradlew :desktopapp:jpackage +``` + +Requirements[^7] for building on: +- Fedora: `rpm-build` +- Debian: `fakeroot` +- macOS: Xcode command line tools are required when the `--mac-sign` or `--icon` options are used. +- Windows: WiX 3.0 or later is required + + [^1]: https://gradle.org/release-checksums/ [^2]: https://docs.gradle.org/7.4.1/userguide/platforms.html#sub:platforms-vs-catalog [^3]: https://docs.gradle.org/7.4.1/userguide/platforms.html#sub:version-catalog-declaration [^4]: https://docs.gradle.org/current/userguide/dependency_management_terminology.html#sub:terminology_dependency_constraint [^5]: https://docs.gradle.org/7.4.1/userguide/rich_versions.html -[^6]: https://docs.gradle.org/current/userguide/java_platform_plugin.html \ No newline at end of file +[^6]: https://docs.gradle.org/current/userguide/java_platform_plugin.html +[^7]: https://docs.oracle.com/en/java/javase/17/jpackage/packaging-overview.html#GUID-786E15C0-2CE7-4BDF-9B2F-AC1C57249134 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index de5ce7f329..6a1142af15 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,7 @@ bouncycastle-lib = { strictly = '1.67' } # Oldest version without known CVE google-gson-lib = { strictly = '2.9.0' } google-guava-lib = { strictly = '31.1-jre' } i2p-lib = { strictly = '1.7.0' } +jpackage-plugin = { strictly = '1.3.1' } junit-jupiter-lib = { strictly = '5.8.2' } kotlindsl-plugin = { strictly = '2.1.7' } logback-lib = { strictly = '1.2.11' } @@ -17,6 +18,7 @@ lombok-lib = { strictly = '1.18.22' } openjfx-plugin = { strictly = '0.0.12' } protobuf-plugin = { strictly = '0.8.18' } protobuf-java-lib = { strictly = '3.19.4' } +shadow-plugin = { strictly = '7.1.2' } slf4j-lib = { strictly = '1.7.36' } typesafe-config-lib = { strictly = '1.4.2' } @@ -51,5 +53,7 @@ i2p = ['i2p-core', 'i2p-router', 'i2p-streaming'] # `alias(libs.plugins.protobuf)` mechanism, there is no risk of loading multiple versions. [plugins] kotlindsl = { id = 'org.gradle.kotlin.kotlin-dsl', version.ref = 'kotlindsl-plugin' } +jpackage = { id = 'org.panteleyev.jpackageplugin', version.ref = 'jpackage-plugin' } openjfx = { id = 'org.openjfx.javafxplugin', version.ref = 'openjfx-plugin' } -protobuf = { id = 'com.google.protobuf', version.ref = 'protobuf-plugin' } \ No newline at end of file +protobuf = { id = 'com.google.protobuf', version.ref = 'protobuf-plugin' } +shadow = { id = 'com.github.johnrengelman.shadow', version.ref = 'shadow-plugin' } \ No newline at end of file From 1938463eac5473ca74c7e63b4cd21583efbaa8d9 Mon Sep 17 00:00:00 2001 From: alkum Date: Sat, 9 Apr 2022 11:29:45 +0200 Subject: [PATCH 2/2] Cleanup buildDir before packaging binaries Ensure the project works with a clean build directory. --- desktopapp/build.gradle | 19 +++++++++++++++---- docs/dev-gradle.md | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/desktopapp/build.gradle b/desktopapp/build.gradle index 3c78a744b5..be9e202238 100644 --- a/desktopapp/build.gradle +++ b/desktopapp/build.gradle @@ -86,7 +86,12 @@ shadowDistTar.enabled = false tasks.jpackage { dependsOn rootProject.clean - dependsOn tasks.build, tasks.shadowJar + dependsOn tasks.clean // Ensure fresh buildDir for every jpackager binary build + dependsOn tasks.jar, tasks.shadowJar + + // The jpackageTempDir stores temp files used by jpackage for building the installers + // It can be inspected in order to troubleshoot the packaging process + File jpackageTempDir = new File(buildDir, "jpackage-temp") appName = "Bisq 2" // Remove the -SNAPSHOT suffix from the version string (originally defined in build.gradle) @@ -97,13 +102,14 @@ tasks.jpackage { vendor = 'Bisq' mainClass = "bisq.desktopapp.Main" mainJar = jar.archiveFileName.get() - verbose = true + verbose = false // arguments = --arguments
destination = "$buildDir/$distsDirName" input = "$buildDir/$libsDirName" licenseFile = "../LICENSE" // resourceDir = --resource-dir // TODO runtimeImage = System.getProperty("java.home") + temp = jpackageTempDir // launchers = --add-launcher = // TODO add multiple launchers? desktopapp / satoshiapp winMenu = true @@ -138,8 +144,9 @@ tasks.jpackage { } linux { - // Had issues when using package-manager-installed-jdk - // Worked well when using IntelliJ IDEA SDKs (File > Project Structure > SDKs > + sign > Download JDK + // Setting runtimeImage to java.home failed when using JDK from package manager (user vs root ownership of files?) + // runtimeImage can alternatively be set to a downloaded and extracted JDK + // Worked well when using IntelliJ IDEA SDKs (File > Project Structure > SDKs > + > Download JDK) runtimeImage = "/home/user/.jdks/openjdk-17.0.2" // icon = "icons/icons.ico" // TODO } @@ -155,6 +162,10 @@ tasks.jpackage { '-Dbisq.networkServiceConfig.seedAddressByTransportType.clear.1=127.0.0.1:8001' ] + doFirst() { + jpackageTempDir.mkdirs() + } + doLast() { File binariesFolderPath = new File("$buildDir/$distsDirName") ant.checksum(algorithm: 'SHA-256') { diff --git a/docs/dev-gradle.md b/docs/dev-gradle.md index 8a8e88cc2a..9f7043379a 100644 --- a/docs/dev-gradle.md +++ b/docs/dev-gradle.md @@ -64,6 +64,8 @@ Platform-specific binaries and installers can be generated with ./gradlew :desktopapp:jpackage ``` +Optionally add the `--info` flag at the end for a more verbose output. + Requirements[^7] for building on: - Fedora: `rpm-build` - Debian: `fakeroot`