Java Compiler
Elide comes with an in-built 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 -- that acts identical 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 | Change to the given directory and include all files from it |
-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.java`You 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.java`Like 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.
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 Src.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" } } } }