簡體   English   中英

使用 Gradle 加 JavaFX 和依賴項構建 Java 11 項目

[英]Building Java 11 Project using Gradle plus JavaFX and dependencies

我正在嘗試構建我的 Java 11 項目以具有可執行的 jar(FatJar、SuperJar,無論其名稱如何)或 EXE 或任何形式的可運行版本,甚至是批處理文件(使用應用程序)。 我嘗試的一切要么得到 JavaFX 丟失,要么我的依賴項包括不可見的包並且錯誤消失了。

這是我的 build.gradle

plugins {
    id 'application'
    id 'java'
    id 'maven-publish'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'edu.sc.seis.launch4j' version '2.4.6'
    id 'org.beryx.jlink' version '2.12.0'
}

application {
    mainClassName = 'sassa.sassa.Main'
}


repositories {
    mavenLocal()
    maven {
        url = uri('https://jitpack.io')
    }

    maven {
        url = uri('https://repo.maven.apache.org/maven2')
    }
}

javafx {
    version = "11.0.2"
    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.graphics' ]
}

jlink {
    launcher {
        name = 'sassa'
    }
}

dependencies {
    implementation 'com.github.toolbox4minecraft:amidst:v4.4-beta1'
    implementation 'com.googlecode.json-simple:json-simple:1.1.1'
}

jar {
    manifest {
        attributes("Manifest-Version": "1.0",
                "Main-Class": "sassa.main.Main");
    }
}
compileJava {
    doFirst {
        println "CLASSPATH IS $classpath.asPath"
        options.compilerArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.graphics',
                '--add-modules', 'javafx.controls',
                '--add-modules', 'javafx.fxml'
        ]
        classpath = files()
    }
}

task fatJar(type: Jar) {
    manifest.from jar.manifest
    classifier = 'all'
    from {
        configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    } {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
    }
    with jar
}

launch4j {
    mainClassName = 'sassa.main.Main'
    icon = "${projectDir}/src/main/resources/sassa/sassa.ico"
    jreMinVersion = '11'
    jreMaxVersion = '14'
    jdkPreference = 'preferJre'
    initialHeapSize = 128
    maxHeapSize = 512
    stayAlive = false
    bundledJre64Bit = true
    dontWrapJar = true
    bundledJrePath = 'jre'
}

group = 'sassa'
version = '0.5.0'
sourceCompatibility = '11'

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

Also for the layout of the project it is on github (I was using maven before but figured Gradle might work better. (The maven code is still on github) https://github.com/Zodsmar/SeedSearcherStandaloneTool/tree/development

從字面上看,我已經嘗試了一切,但我似乎無法獲得可構建的版本來分發......

此外,我還閱讀了關於 module.info 文件的信息,我沒有任何文件,我想要一個簡單的 build.gradle,它只包含構建可執行文件所需的一切。

對於任何遇到此問題並想知道我如何修復它的人。 我創建了一個 Gradle 構建任務,然后能夠構建 Jars、EXE、Tar 和 Zip 這是 Z8ED1A7716936C2D7ZZAD9:


plugins {
    id 'application'
    id 'java'
    id 'maven-publish'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'edu.sc.seis.launch4j' version '2.4.6'
}

dependencies {
    implementation 'com.googlecode.json-simple:json-simple:1.1.1'
    implementation ('com.github.KaptainWutax:BiomeUtils:master-SNAPSHOT') {
        transitive = false;
        changing = true;
    }
    implementation ('com.github.KaptainWutax:FeatureUtils:master-SNAPSHOT')
    {
        transitive = false;
        changing = true;
    }
    implementation ('com.github.KaptainWutax:SeedUtils:master-SNAPSHOT')
    {
        transitive = false;
        changing = true;
    }
}


group = 'sassa'
version = 'v0.6.0'
sourceCompatibility = '1.8'
String stringVersion = version

javafx {
    version = "11.0.2"
    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.graphics' ]
}

application {
    mainClassName = 'sassa.main.Main'
}
jar {
    manifest {
        attributes 'Main-Class': 'sassa.main.Main'
    }
    from {
        configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

launch4j {
    mainClassName = 'sassa.main.Main'
    outfile = group + "-" + stringVersion + ".exe"
    icon = "${projectDir}/src/main/resources/sassa/sassa.ico"
}

repositories {
    mavenLocal()
    maven {
        url = uri('https://jitpack.io')
    }

    maven {
        url = uri('https://repo.maven.apache.org/maven2')
    }
}

task buildAll(type: GradleBuild) {
    tasks = ['jar', 'createExe', 'assemble']
}

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM