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

Resolve dependency issues #407

Merged
merged 7 commits into from
Apr 23, 2024
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
106 changes: 53 additions & 53 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ description = "MQTT CLI is a tool that provides a feature rich command line inte
"various MQTT clients simultaneously and supports MQTT 5.0 and MQTT 3.1.1 "

application {
mainClass.set("com.hivemq.cli.MqttCLIMain")
mainClass = "com.hivemq.cli.MqttCLIMain"
}

/* ******************** java ******************** */

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
languageVersion = JavaLanguageVersion.of(21)
}
}

tasks.compileJava {
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(8))
})
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(11)
}
}

tasks.jar {
Expand All @@ -75,11 +75,11 @@ tasks.jar {
}

tasks.jar {
archiveClassifier.set("plain")
archiveClassifier = "plain"
}

tasks.shadowJar {
archiveClassifier.set("")
archiveClassifier = ""
}

/* ******************** dependencies ******************** */
Expand Down Expand Up @@ -160,11 +160,11 @@ dependencies {

val generateHivemqOpenApi by tasks.registering(GenerateTask::class) {
group = "hivemq"
generatorName.set("java")
inputSpec.set(hivemqOpenApi.singleFile.path)
outputDir.set(layout.buildDirectory.dir("tmp/$name").get().asFile.absolutePath)
apiPackage.set("com.hivemq.cli.openapi.hivemq")
modelPackage.set("com.hivemq.cli.openapi.hivemq")
generatorName = "java"
inputSpec = hivemqOpenApi.singleFile.path
outputDir = layout.buildDirectory.dir("tmp/$name").get().asFile.absolutePath
apiPackage = "com.hivemq.cli.openapi.hivemq"
modelPackage = "com.hivemq.cli.openapi.hivemq"
configOptions.put("dateLibrary", "java8")
configOptions.put("hideGenerationTimestamp", "true")

Expand All @@ -184,11 +184,11 @@ val generateHivemqOpenApi by tasks.registering(GenerateTask::class) {

val generateSwarmOpenApi by tasks.registering(GenerateTask::class) {
group = "swarm"
generatorName.set("java")
inputSpec.set(swarmOpenApi.singleFile.path)
outputDir.set(layout.buildDirectory.dir("tmp/$name").get().asFile.absolutePath)
apiPackage.set("com.hivemq.cli.openapi.swarm")
modelPackage.set("com.hivemq.cli.openapi.swarm")
generatorName = "java"
inputSpec = swarmOpenApi.singleFile.path
outputDir = layout.buildDirectory.dir("tmp/$name").get().asFile.absolutePath
apiPackage = "com.hivemq.cli.openapi.swarm"
modelPackage = "com.hivemq.cli.openapi.swarm"
configOptions.put("dateLibrary", "java8")
configOptions.put("hideGenerationTimestamp", "true")

Expand Down Expand Up @@ -356,9 +356,9 @@ tasks.named("forbiddenApisIntegrationTest") { enabled = false }
//checks for java installations prior the execution.

cliNative {
graalVersion.set(libs.versions.graal)
javaVersion.set(libs.versions.javaNative)
javaVersion = libs.versions.javaNative
}
val majorJavaNativeVersion = libs.versions.javaNative.get().substringBefore(".")

//reflection configuration files are currently created manually with the command: ./gradlew -Pagent agentMainRun --stacktrace
//this yields an exception as the Graal plugin is currently quite buggy. The files are created nonetheless.
Expand All @@ -367,23 +367,20 @@ val agentMainRun by tasks.registering(JavaExec::class) {
group = "native"

val launcher = javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(libs.versions.javaNative.get()))
vendor.set(JvmVendorSpec.GRAAL_VM)

languageVersion = JavaLanguageVersion.of(majorJavaNativeVersion)
vendor = JvmVendorSpec.GRAAL_VM
}
javaLauncher.set(launcher)
javaLauncher = launcher
classpath = sourceSets.main.get().runtimeClasspath
mainClass.set("com.hivemq.cli.graal.NativeMain")
mainClass = "com.hivemq.cli.graal.NativeMain"
}

val nativeImageOptions by graalvmNative.binaries.named("main") {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(libs.versions.javaNative.get()))
vendor.set(JvmVendorSpec.GRAAL_VM)
})
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(majorJavaNativeVersion)
vendor = JvmVendorSpec.GRAAL_VM
}
buildArgs.add("-Dio.netty.noUnsafe=true")
buildArgs.add("-H:+ReportExceptionStackTraces")
buildArgs.add("-H:+TraceServiceLoaderFeature")
buildArgs.add("--no-fallback")
buildArgs.add("--enable-https")
buildArgs.add("--features=com.hivemq.cli.graal.BouncyCastleFeature")
Expand All @@ -396,13 +393,16 @@ val nativeImageOptions by graalvmNative.binaries.named("main") {
"org.jctools.util.UnsafeAccess," +
"io.netty.util.ReferenceCountUtil," +
"io.netty.util.ResourceLeakDetector," +
"io.netty.util.ResourceLeakDetector\$Level," +
"io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueue," +
"io.netty.util.internal.shaded.org.jctools.queues.BaseSpscLinkedArrayQueue," +
"io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess," +
"io.netty.util.CharsetUtil," +
"io.netty.util.internal.SystemPropertyUtil," +
"io.netty.util.internal.PlatformDependent," +
"io.netty.util.internal.PlatformDependent0," +
"io.netty.util.internal.PlatformDependent\$1," +
"io.netty.util.internal.PlatformDependent\$2," +
"io.netty.util.internal.logging.JdkLogger," +
"io.netty.buffer.AbstractByteBufAllocator"
)
Expand Down Expand Up @@ -439,9 +439,9 @@ val nativeImageOptions by graalvmNative.binaries.named("main") {
}

graalvmNative {
toolchainDetection.set(false)
toolchainDetection = false
agent {
defaultMode.set("standard")
defaultMode = "standard"
tasksToInstrumentPredicate.set { t -> t == agentMainRun.get() }
}
binaries {
Expand All @@ -453,8 +453,8 @@ graalvmNative {

val buildBrewZip by tasks.registering(Zip::class) {

archiveClassifier.set("brew")
destinationDirectory.set(layout.buildDirectory.dir("packages/homebrew"))
archiveClassifier = "brew"
destinationDirectory = layout.buildDirectory.dir("packages/homebrew")

into("brew") {
from(tasks.shadowJar)
Expand Down Expand Up @@ -537,24 +537,24 @@ val buildRpmPackage by tasks.registering(Copy::class) {
/* ******************** windows zip ******************** */

launch4j {
headerType.set("console")
mainClassName.set(application.mainClass.get())
icon.set("$projectDir/icons/05-mqtt-cli-icon.ico")
headerType = "console"
mainClassName = application.mainClass.get()
icon = "$projectDir/icons/05-mqtt-cli-icon.ico"
setJarTask(tasks.shadowJar.get())
copyConfigurable.set(emptyList<Any>())
copyright.set("Copyright 2019-present HiveMQ and the HiveMQ Community")
companyName.set("HiveMQ GmbH")
downloadUrl.set("https://openjdk.java.net/install/")
jreMinVersion.set("1.8")
windowTitle.set("MQTT CLI")
version.set(project.version.toString())
textVersion.set(project.version.toString())
copyConfigurable = emptyList<Any>()
copyright = "Copyright 2019-present HiveMQ and the HiveMQ Community"
companyName = "HiveMQ GmbH"
downloadUrl = "https://openjdk.java.net/install/"
jreMinVersion = "1.8"
windowTitle = "MQTT CLI"
version = project.version.toString()
textVersion = project.version.toString()
}

val buildWindowsZip by tasks.registering(Zip::class) {

archiveClassifier.set("win")
destinationDirectory.set(layout.buildDirectory.dir("packages/windows"))
archiveClassifier = "win"
destinationDirectory = layout.buildDirectory.dir("packages/windows")

from("packages/windows") {
filter { it.replace("@@exeName@@", launch4j.outfile.get()) }
Expand All @@ -573,23 +573,23 @@ val buildPackages by tasks.registering {

githubRelease {
token(System.getenv("githubToken"))
draft.set(true)
draft = true
releaseAssets(
tasks.shadowJar,
buildBrewZip,
buildDebianPackage.map { fileTree(it.destinationDir) },
buildRpmPackage.map { fileTree(it.destinationDir) },
buildWindowsZip,
)
allowUploadToExisting.set(true)
allowUploadToExisting = true
}

/* ******************** Update the Homebrew-Formula with the newly built package ******************** */

gitPublish {
repoUri.set("https://github.com/hivemq/homebrew-mqtt-cli.git")
branch.set("master")
commitMessage.set("Release version v${project.version}")
repoUri = "https://github.com/hivemq/homebrew-mqtt-cli.git"
branch = "master"
commitMessage = "Release version v${project.version}"
contents.from(buildBrewFormula)
}

Expand All @@ -612,7 +612,7 @@ jib {
/* ******************** platform distribution ******************** */

distributions.shadow {
distributionBaseName.set("mqtt-cli")
distributionBaseName = "mqtt-cli"
contents {
from("README.txt")
}
Expand Down
15 changes: 7 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
[versions]
apache-commonsIO = "2.16.0"
apache-commonsIO = "2.16.1"
apache-commonsLang = "3.14.0"
apache-commonsText = "1.11.0"
awaitility = "4.2.1"
bouncycastle = "1.77"
bouncycastle = "1.78"
dagger = "2.51.1"
graal = "22.3.0"
graalvm-nativeImage-svm = "22.0.0.2"
graalvm-nativeImage-svm = "24.0.1"
gson = "2.10.1"
gsonFire = "1.9.0"
guava = "33.1.0-jre"
hivemq-communityEditionEmbedded = "2024.3"
hivemq-mqttClient = "1.3.3"
hivemq-testcontainer = "2.0.0"
javaNative = "17"
javaNative = "21.0.2"
javax-annotation-api = "1.3.2"
jetbrains-annotations = "24.1.0"
jline = "3.21.0"
jline = "3.25.1"
jsr305 = "3.0.2"
junit-jupiter = "5.10.2"
junit-pioneer = "2.2.0"
Expand All @@ -25,7 +24,7 @@ mockito = "5.11.0"
netty = "4.1.109.Final"
okhttp = "4.12.0"
openCsv = "5.9"
picocli = "4.7.0"
picocli = "4.7.5"
swagger-annotations = "1.6.14"
testcontainers = "1.19.7"
tinylog = "2.7.0"
Expand Down Expand Up @@ -75,7 +74,7 @@ tinylog-impl = { module = "org.tinylog:tinylog-impl", version.ref = "tinylog" }
[plugins]
defaults = { id = "io.github.sgtsilvio.gradle.defaults", version = "0.2.0" }
forbiddenApis = { id = "de.thetaphi.forbiddenapis", version = "3.7" }
gitPublish = { id = "org.ajoberstar.git-publish", version = "3.0.1" }
gitPublish = { id = "org.ajoberstar.git-publish", version = "4.2.2" }
githubRelease = { id = "com.github.breadmoirai.github-release", version = "2.5.2" }
graalvm-native = { id = "org.graalvm.buildtools.native", version = "0.10.1" }
jib = { id = "com.google.cloud.tools.jib", version = "3.4.2" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import com.hivemq.cli.native_image.extensions.CliNativeExtensionImpl
import com.hivemq.cli.native_image.tasks.DownloadGraalJVMTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.RelativePath
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.register
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import java.io.File


class CliNativeImagePlugin : Plugin<Project> {
Expand All @@ -26,68 +29,58 @@ class CliNativeImagePlugin : Plugin<Project> {
val downloadTask = project.tasks.register<DownloadGraalJVMTask>("downloadGraalJvm") {
group = "native"
description = "Configures the correct download for Graal"
graalVersion.set(extension.graalVersion)
javaVersion.set(extension.javaVersion)
downloadBaseUrl.set(extension.graalBaseUrl)
}

val extractTask = project.tasks.register<Exec>("extractGraalJvm") {
group = "native"
description = "Unzips the Graal JVM into the auto provisioning JDKS folder"
dependsOn(downloadTask)

workingDir(downloadTask.flatMap { it.jdksDirectory })
commandLine("tar", "-xzf", downloadTask.flatMap { it.graalDownload }.get())
inputs.file(downloadTask.flatMap { it.graalDownloadFile })
outputs.dir(downloadTask.flatMap { it.jdksDirectory.dir(it.graalFolderName) })
LukasBrand marked this conversation as resolved.
Show resolved Hide resolved

workingDir(downloadTask.flatMap { it.jdksDirectory.dir(it.graalFolderName) })
commandLine("tar", "-xzf", downloadTask.flatMap { it.graalDownloadFile }.get(), "--strip-components=1")
}

val extractTaskWindows = project.tasks.register<Copy>("extractGraalJvmWindows") {
group = "native"
description = "Unzips the Graal JVM into the auto provisioning JDKS folder"
dependsOn(downloadTask)

from(project.zipTree(downloadTask.flatMap { it.graalDownload }.get()))
inputs.file(downloadTask.flatMap { it.graalDownloadFile })

from(project.zipTree(downloadTask.flatMap { it.graalDownloadFile }.get()))
into(downloadTask.flatMap { it.jdksDirectory })
eachFile {
val originalPath = relativePath.pathString
val parts: MutableList<String> = originalPath.split("/").toMutableList()
parts[0] = downloadTask.flatMap { it.graalFolderName }.get()
val newPath = parts.joinToString("/")
relativePath = RelativePath(!this.isDirectory, newPath)
}
doLast {
destinationDir = downloadTask.flatMap { it.jdksDirectory.dir(it.graalFolderName) }.get().asFile
}
}


project.tasks.register<Exec>("installNativeImageTooling") {
project.tasks.register("installNativeImageTooling") {
group = "native"
description = "Installs the native-image tooling and declares the Graal as auto provisioned"
description = "Declares the GraalVM installation as auto provisioned"

val graalVMFolderProvider: Provider<File>
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows) {
dependsOn(extractTaskWindows)
val graalDirectory = extractTaskWindows.map { it.destinationDir }
.zip(downloadTask.flatMap { it.graalFolderName }) { jdkFolder, graalFolder ->
jdkFolder.resolve(graalFolder)
}
workingDir(graalDirectory)
commandLine("cmd", "/C", getGuPath(), "install", "native-image")
doLast {
graalDirectory.get().resolve("provisioned.ok").createNewFile()
}
graalVMFolderProvider = extractTaskWindows.map { it.outputs.files.singleFile }
inputs.dir(graalVMFolderProvider)
} else {
dependsOn(extractTask)
workingDir(extractTask.map { it.outputs.files.singleFile })
commandLine(getGuPath(), "install", "native-image")
doLast {
extractTask.map { it.outputs.files.singleFile }.get().resolve("provisioned.ok").createNewFile()
}
graalVMFolderProvider = extractTask.map { it.outputs.files.singleFile }
inputs.dir(graalVMFolderProvider)
}
}
}
outputs.file(graalVMFolderProvider.get().resolve("provisioned.ok"))

private fun getGuPath(): String {
return if (DefaultNativePlatform.getCurrentOperatingSystem().isLinux) {
"./bin/gu"
} else if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows) {
"bin\\gu"
} else if (DefaultNativePlatform.getCurrentOperatingSystem().isMacOsX) {
"./Contents/Home/bin/gu"
} else {
throw IllegalStateException(
"Unsupported operating system. (${DefaultNativePlatform.getCurrentOperatingSystem().displayName}"
)
doLast {
graalVMFolderProvider.get().resolve("provisioned.ok").createNewFile()
}
}
}
}
Loading
Loading