Java Compiler
Elide comes with a built-in Java compiler. It supports Java SDK up to version 25.
Elide Java Compiler is exposed in two ways.
- Drop-in usage —
elide javac -- [OPTION...]passes arguments directly to the built-in JDKjavactool. - Build system integration —
elide buildcompiles source files automatically based on declarations inelide.pkl.
Drop-in Usage
Drop-in usage is called via elide javac -- and acts identically to normal javac.
elide javac invocations use the following format:
elide javac -- < javac options> <source files>-- separates Elide and javac-specific options.
There are no Elide-specific options before -- at this time. The -- separator is still required.
Common Javac Options
elide javac supports most of the modern Java options. This is not an exhaustive list.
| Flag | Description |
|---|---|
@ | Reads options and filenames from file |
—class-path DIR, -cp DIR | Specify where to find user class files |
-d DIR | Specify where to place generated class files. |
-h DIR | Specify where to place generated native header files |
-s DIR | Specify where to place generated source files |
-g | Generate all debugging info |
—module MODULE | Compile only the specified module(s) |
—module-path PATH, -p PATH | Specify where to find application modules |
—module-source-path PATH | Specify where to find input source files for multiple modules |
-v, —verbose | Verbose output |
elide javac -- --helpUsage Example
As an example, let's say you have the following directory set up for your project.
src
| HelloWorld.java
| ByeWorld.java
README.mdTo compile a specific source file, from the root of the project, you need to make the following call.
elide javac -- ./src/HelloWorld.javaYou will notice that the src directory has a compiled .class file appear. The project now looks like this.
src
| HelloWorld.java
| HelloWorld.class
| ByeWorld.java
README.mdIn order to specify build directory, pass the -d flag.
elide javac -- -d ./build/ ./src/HelloWorld.javaLike regular javac, Elide will create a build directory and output all built .class there.
build
| HelloWorld.class
src
| HelloWorld.java
| ByeWorld.java
README.mdAs you can see, by passing standard javac options after -- flag, you can use elide javac like a standard javac.
Bazel Persistent Worker Mode
elide javac implements Bazel's persistent worker protocol so build systems
can amortise JVM startup and warm classloader state across many compile
actions. Bazel itself spawns the worker; you do not typically invoke this
mode by hand.
elide javac --persistent_workerWith the flag set, the compiler reads length-delimited protobuf WorkRequest
messages from stdin, dispatches each request through the embedded JDK
javac, and emits a WorkResponse (length-delimited proto) on stdout.
Diagnostics produced by the underlying compiler are captured into the
response's output field so Bazel can surface them on the requesting target.
The response frame is written to the raw stdout file descriptor so the
in-process stdio redirection used to capture diagnostics cannot corrupt the
on-the-wire framing.
The worker is multiplex-safe: request_id is echoed on every response, so
Bazel may run it as a multiplex worker (--worker_multiplex, advertised via
supports-multiplex-workers) and issue concurrent WorkRequests to a single
process — they queue on stdin, are matched by request_id, and complete
correctly without interleaving or corruption. Singleplex pools
(--worker_max_instances=N) are equally supported. Compiles run serially within
the process (the embedded javac is not thread-safe at parse-args / exec time),
so multiplex consolidates onto one warm process rather than adding intra-process
compile parallelism. The same protocol is exposed for elide kotlinc.
Build System Integration
When using elide build with an elide.pkl project file, Java source compilation is handled automatically by the build task graph.
It is possible to only compile Java source files by running elide build :compile-java-main.
Declaring Source Files
Declaring Java source files in a source block will result in their automatic compilation during elide build call.
amends "elide:project.pkl"
import "elide:Sources.pkl" as Sources
sources {
["main"] = new Sources.SourceSetSpec {
paths {
"src/main/java<<>>*.java"
}
}
}Setting Compiler Options
To set specific Elide Java Compiler options, pass flags into the elide.pkl.
Example: ```pkl jvm { java { compiler { flags { "-verbose" } } } }