TheBoegl / gradle-launch4j

A gradle-plugin to create windows executables with launch4j
Apache License 2.0
298 stars 40 forks source link

Add support for not specifying a jar file #149

Closed jpschewe closed 1 year ago

jpschewe commented 1 year ago

According to https://launch4j.sourceforge.net/docs.html the jar tag isn't required. I would like the ability to specify a configuration without the jar tag in the created XML file. In my case I don't create a jar for my application, but rather include the class files and the dependent jar files in my executable directory. To work around this issue I've been specifying the jar attribute pointing to one of my libraries. Now I've created a dummy jar task to return one of the dependent libraries. However it would be nice to not need to do that.

Example build.gradle file here.

// -*- java -*-

buildscript {
    repositories {
        maven { url 'https://boegl.jfrog.io/artifactory/snapshots-gradle-dev-local/' }
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'edu.sc.seis.launch4j:launch4j:latest.integration'

      // needs to use old plugin mechanism otherwise I can't set the extra properties   
      classpath(group: "com.cinnober.gradle", name: "semver-git", version: "3.0.0")
    }
}    

plugins {
    id "java"
    id "distribution"
    //id "edu.sc.seis.launch4j" version "2.5.3"
}

// needs to use old plugin mechanism otherwise I can't set nextVersion and snapshotSuffix
ext.nextVersion = "patch"
ext.snapshotSuffix = "beta.<count>+g<sha><dirty>"
// optionally: ext.dirtyMarker = "-dirty" (default) replaces <dirty> in snapshotSuffix
// optionally: ext.gitDescribeArgs = '--match *[0-9].[0-9]*.[0-9]*' (default) or other arguments for git describe.
apply plugin: "com.cinnober.gradle.semver-git"

apply plugin: 'edu.sc.seis.launch4j'

repositories {
    mavenCentral()
}

ext {
    log4j_version = "2.18.0"
    mainClassName = "fll.Launcher"
}

group = "fll"

java {
    // set version of Java that the source confirms to. 
    // The bytecode will be for this version of Java as well, unless targetCompatibility is specified.
    sourceCompatibility = JavaVersion.VERSION_17
}

tasks.register("dummyJarBuild") {
    // need to specify a jar file that we know will exist as a dependency, 
    // otherwise launch4j will look for the jar file created from the build
    outputs.file("log4j-core-" + project.log4j_version + ".jar")
}

createExe {
    mainClassName = project.mainClassName

    dontWrapJar = true
    errTitle = "FLL-SW"
    classpath = ["%EXEDIR%/classes", "%EXEDIR%/lib/*.jar"]
    jarTask = project.tasks.dummyJarBuild

    maxHeapPercent = 75        

    fileDescription = "FIRST Lego League Scoring Software"
    productName = "FLL-SW"
    copyright = "GPL"

    bundledJrePath = "jdk"
    //bundledJre64Bit = true
    requires64Bit = true
    //bundledJreAsFallback = false

    // should not need to specify this https://github.com/TheBoegl/gradle-launch4j/issues/88        
    //jreMinVersion = project.targetCompatibility

    // for debugging classpath information        
    //headerType = "console"
    jvmOptions = [
    //"-Dlog4j2.debug=true",

    // Add the JAVA 9 specific start-up parameters required by Tomcat
    "--add-opens=java.base/java.lang=ALL-UNNAMED",
    "--add-opens=java.base/java.io=ALL-UNNAMED",
    "--add-opens=java.base/java.util=ALL-UNNAMED",
    "--add-opens=java.base/java.util.concurrent=ALL-UNNAMED",
    "--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED"
    ]
}
TheBoegl commented 1 year ago

You can simply set an empty copyConfigurable to avoid copying anything into the lib folder or, as in your case, add the configuration you want there.

jpschewe commented 1 year ago

Can you provide an example of that? I'm not familiar enough with custom gradle code to find what you are referencing here. Note that I'm not worried about what is copied on the filesystem, that works fine. I'm worried about the structure of the generated XML.