Search code examples
javagradlebuild.gradlegradle-pluginjlink

How to bundle extra files with jlink image


I'm using Gradle with the Badass JLink Plugin to distribute my software. Unfortunately, I can't figure out how to include certain files in the image (e.g. README.md, some test input, etc.). I assume it requires some work in build.gradle, but I've so far not been able to figure it out.

It's easy to do this using the application plugin's distZip functionality by following these instructions, but I prefer to distribute using a jlink image so users don't need to have Java installed.

Is this even possible to do with jlink? If not, it seems like a huge drawback.


Solution

  • Thanks to the useful comments from @VGR, I was able to come up with this solution to my problem in build.gradle:

    def JLINK_DIR = "$buildDir/myApp"
    
    tasks.jlink.doLast {
        copy {
            from("/") {
                include "README.md", "LICENSE"
            }
            into JLINK_DIR + "/docs"
        }
        copy {
            includeEmptyDirs = false
            from("/path/to/sample/input") {
                include "sample_input_1/*"
                include "sample_input_2/*"
                exclude "output"
            }
            into JLINK_DIR + "/sample_input"
        }
    }
    

    The Gradle Docs on copy and the Badass JLink Plugin examples were especially helpful.