[SOLVED] Gradle a deliverable package for windows, mac and linux

I wonder if there is a ready to use gradle snippet which bundles a JME game for delivery. I would like to do this for windows, linux and mac so I can hand it to friends for testing purpose?!

As far I know the SDK does provide a non gradle way but only if I do it purely with SDK without gradle. I guess I’m not the only one :slight_smile:

Any hints are welcome.

1 Like

What I use is launch4j, but there might be alternatives. I think you want to have .exe’s?
Because when they have a JRE, the regular assemble task would be enough, maybe with a batch/shell file.

If you are talking about random people, then here’s what I do. You need to download the jre for each platform though and place it in jre/

(I ommited the x86 versions since they are the same)

task(createx64Exe, type: edu.sc.seis.launch4j.tasks.Launch4jLibraryTask, dependsOn: ['build', 'jar', 'prepareJres']) {
    mainClassName = project.mainClassName
    //outputDir = "distributions/base"
    outfile = project.name + "64.exe"
    dontWrapJar = true
    bundledJrePath = "../jre"
    jreMinVersion = "1.7.0"
    bundledJre64Bit = true
    jreRuntimeBits = "64"
    headerType = "console"
    chdir = "../"
}

task(prepareReleases, dependsOn: ['jar', 'build', 'startScripts', 'createx64Exe', 'createx86Exe'], type: Task) {
    doLast {
                       
        def base = "build/distributions/base";
        
        copy {           
            with distributions.main.getContents()
            from "other/"
            into "$base"
        }
        
        // Windows x86
        copy {
            from "$base";
            into "build/distributions/windows-x86/";
        }
        
        copy {
            from "build/launch4j/" + project.name + ".exe";
            into "build/distributions/windows-x86/bin";
            
        }
        
        copy {
            from "jre/$jreVersion$jreBuild/windows-i586/prepared/";
            into "build/distributions/windows-x86/jre";
        }
        
        // Windows x64
        copy {
            from "$base";
            into "build/distributions/windows-x64/";
        }
        
        copy {
            from "build/launch4j/" + project.name + "64.exe";
            into "build/distributions/windows-x64/bin";
            
        }
        
        copy {
            from "jre/$jreVersion$jreBuild/windows-x64/prepared/";
            into "build/distributions/windows-x64/jre";
        }
        
    }
}

task(zipW64, dependsOn: 'prepareReleases', type: Zip) {
    from "build/distributions/windows-x64/";
    destinationDir file("release");
    appendix "windows-x64";
}

task(release, dependsOn: ['zipW32', 'zipW64'], type: Task) {
}

What prepareReleases does: copy from base (which is the folder I put the output into (distributions.main.getContent())) into a folder per platform. Then I copy launch4j’s exe and the jre into the subfolder.

Now for Linux and Mac you would need to do the same, startScripts will generate some .sh and .bat already which search for system wide jres (so you wouldn’t need launch4j and the jre’s if your friends have installed java).

If you’d want to bundle the jre for linux, you’d need ../jre/java -jar ../MyGame.jar as script or something.
I am uncertain about how and if you could build a MacOs App Package though, thats a bigger topic (which is unneeded for your friends)

1 Like

You might as well take a look at gradle’s Application Plugin and gradle-getdown-plugin.

2 Likes

I like to use fxpackager which can build your java application as native application with embedded JRE :wink:
I use gradle to manage dependencies and the ant script to build native bundles:
https://bitbucket.org/JavaSabr/jme3-spaceshift-editor/src/1602b1464e897feb56623c4b49a3c75ee71a6961/build.gradle?at=master&fileviewer=file-view-default
https://bitbucket.org/JavaSabr/jme3-spaceshift-editor/src/1602b1464e897feb56623c4b49a3c75ee71a6961/build-native.xml?at=master&fileviewer=file-view-default

2 Likes

getdown is a good tool,
I hang it to the bitbucket pipelines. So package goes strait to bitbucked downloads.

1 Like