Elide Gradle Plugin
You can use Elide as a build and dependency tool within Gradle via a plugin.
Elide builds javac as a native image and includes it within the Elide binary. This plugin changes your Gradle build to use Elide's toolchain facilities instead of Gradle's built-in ones.
Additionally, the plugin can be configured for Elide to perform dependency resolution and loading.
The result can be a significant performance improvement for fetching dependencies and compiling code.
Before you start
You'll need an installed copy of Elide. Follow the Installation guide to obtain a copy of Elide.
Installation
1. Create the javac shim in your JAVA_HOME:
$JAVA_HOME/bin/elide-javac
#!/usr/bin/env bash
exec elide javac -- "${@}"2. Mark the shim as executable:
chmod +x $JAVA_HOME/bin/elide-javac3. Setup plugin in your Gradle project:
gradle.properties
elidePluginVersion=latestsettings.gradle.kts
// Use `latest` for the latest version, or any other tag, branch, or commit SHA on this project.
val elidePluginVersion: String by settings
apply(from = "https://gradle.elide.dev/$elidePluginVersion/elide.gradle.kts")build.gradle.kts
plugins {
// The `elideRuntime` catalog is added for you. Add the plugin like this:
alias(elideRuntime.plugins.elide)
}
// Settings here apply on a per-project basis. See below for available settings; all properties
// are optional, and you don't need to include this block at all if you are fine with defaults.
elide {
// Use Elide's Maven resolver and downloader instead of Gradle's. Defaults to `true` when an
// `elide.pkl` file is present in the project root.
enableInstall = true
// Use Elide to compile Java instead of the stock Compiler API facilities used by Gradle.
// Defaults to `true` if the plugin is active in the project at all.
enableJavaCompiler = true
// Enable Elide project awareness for Gradle. For example, build scripts can show up as runnable
// exec tasks within the Gradle build.
enableProjectIntegration = true
// Set the path to the project manifest, expressed in Pkl format. Elide project manifests can
// specify dependencies, build scripts, and other project metadata. Defaults to `elide.pkl` and
// automatically finds any present `elide.pkl` in the active project.
manifest = layout.projectDirectory.file("elide.pkl")
}Usage
Compiling with Elide + Gradle
Elide acts as a full drop-in replacement for javac and kotlinc.
To enable Elide compilation, set enableJavaCompiler = true in build.gradle.kts.
Gradle's JavaCompile tasks are configured to use Elide through isFork = true and forkOptions.executable. These point to a shim in the JAVA_HOME which invokes elide javac -- ... instead of javac ....
As a result, JIT warmup is entirely skipped when compiling Java, allowing for better compiler performance compared to stock javac.
Using Elide for dependency resolution
Elide resolves and fetches Maven dependencies with identical semantics to Maven's own resolver, but with an optimized resolution step through the use of a checked-in lockfile.
To enable Elide dependency resolution, set enableInstall = true in build.gradle.kts.
When activated for use with Gradle, a few changes are made to your build:
- An invocation of
elide installis added during configuration phase. - Gradle is configured for a local Maven repo at
.dev/dependencies/m2, which is where Elide puts resolved JARs. - Thus, when Gradle resolves dependencies, they are already on disk and ready to be used in a classpath.
- In this mode, dependencies are downloaded once and can then be used with both Elide and Gradle.
elide.pkl manifest listing your Maven dependencies. This will change in the future.