How can I add a JVM to an application distribution

Hallo,

I have read the page that shows how to create an application
https://docs.gradle.org/current/userguide/application_plugin.html
but the user needs still to install a JVM

I would like to add to the created application the JVM for windows, linux and mac with the good version.

I’m using Amazon Correto for now.

Technically, the JVM can be seen as:

  • a dependency
  • or as an external resources.

What would be the best way to deal with this ?

1 Like

There is no built-in support for this, at least not yet.
But you can for example register three tasks, one that creates a windows JVM image, one that creates a linux JVM image, and one that creates a mac JVM image and then configure the application distribution to include those JVM images in the distributable archive, and modify the start scripts to use these packaged JVM images, either by manipulating the generated start scripts or by using own templates for the start scripts generation task.

1 Like

Thanks. I need to create custom tasks then.

What about the zip file of the JVM ?
For instance, for windows, i would use amazon-corretto-8-x64-windows-jdk.zip

Can I declare it as dependency easily in order to not download it each time
or do I need to take care of this in the custom task ?

The doc is not straight forward on this.

You could probably declare an ivy repository with custom pattern and artifact metadata to do it, but simply using something like the Download task of GitHub - michel-kraemer/gradle-download-task: Adds a download task to Gradle that displays progress in might be easier and more appropriate.

Thanks. I took the Ivy path.

I got to the distribution phase and here again, it seems that the Distribution plugin does not allow inheritance.

I mean, I have the same distribution for each target os where i copy resources such as documentation
but if I create a new distribution, it does not take any configuration from the main distribution.

I need again to write a custom task ?

Thanks again for your expertise

I thought you want one distribution with all JVM images in there.
So you want three distributions each with their own JVM image?
The contents part of a distribution is a CopySpec and you can explicitly reuse an existing copy spec.
So in Kotlin DSL it would for example be something like

distributions {
    register("windows") {
        contents {
            with(distributions.main.get().contents)
        }
    }
}

In Groovy DSL it should be something like

distributions {
    windows {
        contents {
            with(distributions.main.contents)
        }
    }
}

Yo. What is this magic … !!!

How could I know ? I took a look to the distribution API and there was nothing like that (ie no with function)

Thanks again, I’m going to write something on that.

If found it here but yeah, the usage … is not straightforward in my head.

The “trick” is to know the section Sharing copy specs and to see that distribution.contents is actually a CopySpec :slight_smile:

1 Like

I’ve done this by packing the JDK with the software and distributing as a compressed file for Mac, Linux and Windows. You can see my build file at fll-sw/build.gradle at main · jpschewe/fll-sw · GitHub
Take a look at windowsDistributionDependencies (and similar Mac and Linux ones).

1 Like