JeKa — A Simple Modern Java Build Tool
JeKa is a modern Java build tool focused on simplicity.
When starting with Java, developers usually just write some code, compile it, and run it. However, this is not enough to create useful Java applications or libraries that others can reuse. To build something practical in Java, we need to:
- Use third-party libraries (e.g., Guava, Gson, Commons CLI, etc.)
- Package and deploy the application/library so others can use it.
This is often done with traditional build tools like Maven or Gradle. These tools require significant learning and can involve tedious configuration.
A simpler alternative is JBang, which lets you write almost single-file Java apps and easily share them.
On the other hand, Jeka offers simple dependency management and deployment ala JBang while allowing you to build standard multi-class applications or libraries with proper tests included.
🏗️ Scaffold a New Code Base
JeKa can operate in both base and project modes. The base mode uses a simpler structure, where the entire codebase resides in a single folder and dependencies are declared directly within Java classes using annotations.
Tip: To list base available options, execute: jeka base: --doc
.
To create a base structure, ready for starting coding right away, execute:
jeka base: scaffold scaffold.kind=APP
You’ll get the following codebase layout:
.
├── jeka-src <- Source root directory
│ ├── _dev <- Optional package containing all non-prod (build and test)
│ │ ├── test
│ │ └── Custom.java
│ └── app <- Suggested base package for production code/resources
│ └── App.java
├── jeka-output <- Generated dir where artefacts as jars, classes, reports or doc are generated
├── jeka.properties <- Build configuration (Java and jeka version, kbean configurations, ...)
└── README.md <- Describes available build commands
All your Java code should be located in the jeka-src folder.
The _dev
package is a special directory for source code and dependencies used exclusively for development purposes (e.g., tests, builds). If you're new to Java, you can ignore or delete it.
The scaffolded example includes an App class within the app package. You are free to add or modify classes in any package as you see fit.
🔄 Sync with IntelliJ
To synchronize with IntelliJ, execute:
jeka intellij: sync --force
📦 Add Dependencies
The App.java class uses the @JkDep
annotation to reference a library. You can add as many libraries as needed. It’s a good practice to declare all dependencies in the same base class.
@JkDep("com.github.lalyos:jfiglet:0.0.9")
@JkDep("com.fasterxml.jackson:jackson-bom:2.18.2@pom")
@JkDep("com.fasterxml.jackson.core:jackson-core")
@JkDep("com.fasterxml.jackson.core:jackson-annotations")
public class App {
public static void main(String[] args) {
...
}
}
See details on dependency notations.
Additionally, you can simply copy and paste JAR files into the following directory, and they will automatically be included as dependencies:
├── jeka-boot <- Jars included in the production classpath.
Declare non-prod dependencies
If you declare the @JkDev
annotation within the _dev
package, any dependencies it references will be excluded from the final production build.
package _dev;
@JkDep("org.junit:junit-bom:5.12.2@pom")
@JkDep("org.junit.platform:junit-platform-launcher")
@JkDep("org.junit.jupiter:junit-jupiter")
@JkDep("org.mockito:mockito-junit-jupiter:5.15.2")
class Custom extends KBean {
...
}
🏃♂️ Run your Application
The application can be run using:
jeka --program arg0 args1 ... # or `jeka -p` for short
To clean the compilation before starting, use the --clean
or -c
option. -p
stands for --program
shorthand.
jeka -c -p arg0 args1 ... # or `jeka -p` for short
📚 Create a Library
If you want to write a library, instead of an application, you need to declare both moduleId and versioning in order to publish it on a Maven repository:
@base.moduleId=org.example:my-lib
@base.version=1.0.0-SNAPSHOT
Now, you can publish your library by executing:
jeka maven: publish
🧪 Test your Code
The scaffolded code already contains a _dev.test.MyTest
test class, ready to run.
.
├── jeka-src
│ ├── _dev
│ │ └── test
│ │ └── MyTest.java
You can add more tests in any package you like. However, keep in mind that test classes not located in the _dev
package (or its sub-packages) will be included in the production JAR as dead code.
☕ Change Java Version
Nowadays, Java evolves rapidly, with new releases every six months. JeKa provides a very convenient way to switch between Java versions. Simply specify the desired version in the jeka.properties file:
jeka.java.version=24
This will automatically install JDK 24 during the next application compile or run.
🌍 Distribute Worldwide — No Packaging Needed
With JeKa, you don’t need to package your project into binaries or upload it to a hosting service. Just push your code to GitHub (or any Git repository), and it’s instantly runnable by anyone, anywhere.
How it works:
- Push your project to GitHub or any accessible Git repository.
- Anyone can run it with a single command:
jeka -r https://github.com/jeka-dev/demo-cowsay
You can also run a specific version and pass arguments to the application:
jeka -r https://github.com/jeka-dev/demo-cowsay#0.0.2 -p "Hello JeKa"
#0.0.2 refers to the Git tag 0.0.2
"Hello JeKa" is passed as an argument to the application
✅ With JeKa, your Java project becomes globally accessible—no build artifacts, no deployment steps, no hassle.
🧱 Move to Project Mode
As the codebase is growing, you'll might find more confortable in using a full project structure.
.
├── src
│ ├── main <- Java code and reources
│ │ ├── java
│ │ └── resources
│ └── test <- Java code and reources for tests
│ ├── java
│ └── resources
├── jeka-src <- Optional Java (or Kotlin) code for building the project
│ └── Custom.java
├── jeka-output <- Generated dir where artifacts as jars, classes, reports or doc are generated
├── dependencies.txt <- Dependency lists for compile, runtime and testing
├── jeka.properties <- Build configuration (Java and jeka version, kben configurations, ...)
├── jeka.ps <- Optional Powershell script to boot Jeka on Windows
├── jeka <- Optional bash script to boot Jeka on Linuw/MacOS
└── README.md <- Describes available build commands for building the project
Moving to project is easy, to figure out how to do, visit the Build Projects Tutorial.
🔷 Code with Kotlin
You can also write Kotlin code in your codebase. Just specify the Kotlin version you want to use in the jeka.properties
file:
jeka.kotlin.version=2.1.0
Now, you can edit Kotlin code as shown below, seamlessly integrate it with the existing Java code in your codebase, or even create a 100% Kotlin application:
class Greeting {
fun sayHello() : String{
return "hello"
}
}
🛠️ Pre-defined Build Commands
Among others, Jeka provides the following commands:
jeka base: test # Runs tests
jeka base: pack # Runs tests + creates jars
jeka base: runJar # Runs the jar generated by the above command
jeka base: info # Displays project configuration info
jeka base: depTree # Displays dependency trees
Other commands:
jeka native: compile # Compiles to native executable
jeka docker: build # Builds a Docker image for the project
jeka docker: info # Displays info about generated image.
jeka docker: buildNative # Builds a Docker image containing the native executable
jeka docker: infoNative # Displays info about generated native image
jeka maven: publishLocal # Publish artifacts in the local repository
jeka maven: publish # Publish in the defined Maven repository
🏁 Conclusion
Jeka offers a practical mode to start writing real-life Java application without the burden of traditional build tools.
Its polymorphic structure allows handling increasing complexity and size gradually, without sacrificing simplicity.
Resources:
Top comments (0)