Gradle FAQ

How to setup and use Gradle. Also see the Gradle notes

How can I tell Gradle what version of the JDK to use?

Gradle will use the JDK in the class path on your system to execute tasks. If you are using IntelliJ IDEA, you can also specify the version to use in the IDE settings: Settings > Build Tools > Gradle.

Often you want to tell Gradle to compile your code with a specific JDK version. You can specify this in your project configuration files. For example, here’s how you specify JDK 21.

// add this to your build.gradle.kts java { toolchain { languageVersion.set(JavaLanguageVersion.of(21)) } }
// add this to your settings.gradle.kts so that Gradle can download the JDK if needed plugins { id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0") }

How do I create an installer for my program?

For a Compose desktop application, there is a set of Gradle packaging tasks: Gradle > application > Tasks > compose desktop > package. You probably want to packageDistributionForCurrentOS which will build a regular installer for the OS that you’re currently using.

For Android, it’s acceptable to build an APK file (Build > Generate APK) instead of a full installer. This file can be drag-dropped onto a running AVD to run the program.

There are also third-party installation tools if you want something more sophisticated. e.g. Conveyor.

How can I fix an installer that fails?

Here are some common errors to watch out for (all related to the build.gradle.kts configuration file):

  1. You need to specify that you want to include all modules in the installer.
nativeDistributions { includeAllModules = true targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) packageName = "cs346-project" packageVersion = "1.0.0" }
  1. The version property defaults to “1.0-SNAPSHOT”. You MUST change this to the format “1.0.0” - see Semantic Versioning. You should probably be incrementing this with each software release/demo.
group = "com.example" version = "1.0.0"
  1. All libraries don’t fully support JDK 20 and later, so you should probably use an older version of the JDK (see required software). Make sure to set in the project settings (File > Project Structure > Project) and the Gradle project settings (IntelliJ > Settings > Build > Gradle)

If your installer fails when you execute it, try checking some of the other related tasks in the Gradle Menu in IntelliJ. e.g. compose desktop > runDistributable. The Gradle tasks in this section represent the subtasks that the installer builds and if you run them in the IDE, you will get more detailed feedback than you would from running the installer manually.