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.

  1. Drop-in usageelide javac -- [OPTION...] passes arguments directly to the built-in JDK javac tool.
  2. Build system integrationelide build compiles source files automatically based on declarations in elide.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:
shell
 elide javac -- < javac options> <source files>
-- separates Elide and javac-specific options.
Note

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.
FlagDescription
@Reads options and filenames from file
—class-path DIR, -cp DIRChange to the given directory and include all files from it
-d DIRSpecify where to place generated class files.
-h DIRSpecify where to place generated native header files
-s DIRSpecify where to place generated source files
-gGenerate all debugging info
—module MODULECompile only the specified module(s)
—module-path PATH, -p PATHSpecify where to find application modules
—module-source-path PATHSpecify where to find input source files for multiple modules
-v, —verboseVerbose output
To access the full list of possible options use
shell
 elide javac -- --help

Usage Example

As an example, let's say you have the following directory set up for your project.

src
|  HelloWorld.java
|  ByeWorld.java

README.md

To compile a specific source file, from the root of the project, you need to make the following call.

shell
 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.md

In order to specify build directory, pass the -d flag.

shell
 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.md

As 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.

pkl
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" } } } }