Я хотел бы опубликовать его на нашей арт-фабрике, но мне не удалось структурировать файл build.gradle.kts, чтобы иметь возможность:
< ol>
[*]Запустите класс с помощью основного метода; и
[*]Создайте jar-файл, который не зависит от реализации JavaFX для конкретной платформы.
Это где я сейчас:
Код: Выделить всё
import org.gradle.internal.os.OperatingSystem
plugins {
java
application
`maven-publish`
// I can't imagine this is necessary but my module isn't able to import JavaFX without it.
id("org.openjfx.javafxplugin") version "0.0.14"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
val isRelease = project.hasProperty("release")
val appVersion = "0.1" + if (isRelease) "" else "-SNAPSHOT"
val modulePath by lazy { "${configurations.runtimeClasspath.get().asPath}:build/classes/java/main" }
val moduleString by lazy { javafx.modules.joinToString(separator = ",") }
application {
version = appVersion
group = "my.organization.subproject"
mainClass.set("my.organization.subproject.fx.Main")
mainModule.set("AutoMosaic")
}
repositories {
mavenCentral()
}
javafx {
version = "21"
modules("javafx.controls", "javafx.swing")
// When this is enabled, I cannot run the classes with Main methods.
configuration = "compileOnly"
}
val javafxPlatform: String = when {
OperatingSystem.current().isMacOsX && System.getProperty("os.arch") == "aarch64" -> "mac-aarch64" // ARM Mac
OperatingSystem.current().isMacOsX && System.getProperty("os.arch") == "x86_64" -> "mac" // Intel Mac
OperatingSystem.current().isWindows -> "win"
OperatingSystem.current().isLinux -> "linux"
else -> throw GradleException("Unsupported OS for JavaFX")
}
dependencies {
// In an attempt to only rely on platform-neutral dependencies.
compileOnly("org.openjfx:javafx-base:21")
compileOnly("org.openjfx:javafx-controls:21")
compileOnly("org.openjfx:javafx-graphics:21")
compileOnly("org.openjfx:javafx-swing:21")
// To execute Main and Planner locally.
runtimeOnly("org.openjfx:javafx-base:21:$javafxPlatform")
runtimeOnly("org.openjfx:javafx-controls:21:$javafxPlatform")
runtimeOnly("org.openjfx:javafx-graphics:21:$javafxPlatform")
runtimeOnly("org.openjfx:javafx-swing:21:$javafxPlatform")
}
// To create the Main and Planner Gradle tasks that can be run.
fun createJavaExecTask(taskName: String, mainClassName: String) {
tasks.register(taskName) {
group = "application"
mainClass.set(mainClassName)
jvmArgs = listOf(
"--module-path", modulePath,
"--add-modules", moduleString
)
classpath = sourceSets["main"].runtimeClasspath
}
}
// To run these through IDEA, configure Gradle tasks with Tasks and Arguments:
// 1. Main: main
// 2. Planner: planner
// Then they should be runnable via IDEA. The issue is that the module path for the JavaFX jars
// managed by the plugin are incredibly obtuse and can change, so even grabbing them and
// hard-coding them in an Application task yields issues.
createJavaExecTask("main", "my.organization.subproject.fx.Main")
createJavaExecTask("planner", "my.organization.subproject.fx.Planner")
// Print the arguments necessary to configure an IDEA task.
tasks.register("jvmOpts") {
doLast {
println("JVM opts required to make an IDEA task:")
println("--module-path $modulePath --add-modules $moduleString")
}
}
val repositoryUrl = "https://jfrog.organization.edu/artifactory/apt-maven"
val sourcesJar by tasks.registering(Jar::class) {
from(sourceSets.main.get().allSource)
archiveClassifier.set("sources")
}
publishing {
publications {
create("mavenJava") {
groupId = "my.organization.mainproject"
from(components["java"])
artifact(sourcesJar.get())
}
}
repositories {
maven {
val repoPassword: String? by project
val repoUsername: String? by project
url = uri(repositoryUrl + (if (project.hasProperty("release")) { "-releases" } else { "-snapshots" }))
credentials {
username = repoUsername
password = repoPassword
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ble-code-f
Мобильная версия