Project KBean - The Java Build Engine¶
Manages the build and execution of a JVM project.
It contains all information and methods for resolving dependencies, compiling, testing and packaging as JARs.
ProjectKBean
is the core KBean for building JVM projects in JeKa. It acts as the equivalent of the Java Plugin in Maven or Gradle,
wrapping a JkProject instance to provide high-level build automation.
Key Features¶
- Standardized Build Lifecycle: Methods for
compile,test,pack, and more out-of-the-box. - Dependency Management: Automated resolution for compile, runtime, and test classpaths.
- Artifact Creation: Generates regular, fat (uber), shaded, source, and Javadoc JARs.
- Project Introspection: Displays detailed dependency trees and project configurations.
- Git Integration: Automatically infers project versions from Git tags/metadata.
- Extensibility: Foundation for other KBeans to extend the build process (e.g., Docker, Jacoco, Sonarqube).
Core Methods¶
ProjectKBean exposes several methods to automate your build process from the command line:
| Method | Description |
|---|---|
scaffold |
Creates a new project structure and build script skeleton. |
clean |
Deletes the jeka-output directory. |
compile |
Compiles source code and processes resources. |
test |
Compiles and executes unit tests (e.g., JUnit 5). |
pack |
Creates the project's JAR artifacts. |
build |
Complete cycle: clean -> compile -> test -> pack -> checkQuality -> e2eTest. |
info |
Displays project metadata (version, module ID, layout, etc.). |
depTree |
Prints the resolved dependency tree to the console. |
runJar |
Executes the generated JAR file. |
Common Options¶
These properties can be set via command line (e.g., project: javaVersion=17) or in jeka.properties (e.g., @project.javaVersion=17).
| Property | Description | Default |
|---|---|---|
javaVersion |
Target JVM version (e.g., 21, 25). |
Same as JeKa runtime |
test.skip |
If true, tests are not executed. |
false |
pack.jarType |
Type of JAR to produce (REGULAR, FAT). |
REGULAR |
version |
Hardcode the project version. | Inferred from Git |
moduleId |
Maven coordinates (group:name). |
null |
Programmatic Customization¶
Access the underlying JkProject for deep customization, typically within @JkPostInit.
class MyBuild extends KBean {
@JkPostInit(required = true)
private void postInit(ProjectKBean projectKBean) {
JkProject project = projectKBean.project;
// Example: Add a custom compiler option
project.compilation.addJavaCompilerOptions("-Xlint:unchecked");
// Example: Customize the JAR manifest
project.pack.manifest.addMainAttribute("Author", "JeKa Team");
}
}
Annotation Processors¶
Enable processors like Lombok by adding them as compile-only dependencies in jeka.project.deps:
[compile-only]
org.mapstruct:mapstruct-processor:1.6.3
org.projectlombok:lombok:1.18.38
Output directory: jeka-output/generated-sources/annotation-processors.
Extending with Plugins¶
ProjectKBean is designed to be extensible. Many JeKa plugins interact with it to add specific capabilities:
- Jacoco: Collects code coverage during the
testphase. - Sonarqube: Exports project data for static analysis.
- Protobuf: Integrates Protocol Buffers compilation.
- Docker: Packages your project as a Docker image.
Summary¶
Manages the build and execution of a JVM project.
It contains all information and methods for resolving dependencies, compiling, testing and packaging as JARs.
| KBean Initialisation |
|---|
Applies the specified configuration to the underlying JkProject instance. |
This KBean exposes the following fields:
| Field | Description |
|---|---|
| version [String] | Version of the project. Can be used by a CI/CD tool to inject version. |
| moduleId [String] | Module id of the project. Only needed if the project is published on a Maven repository. |
| sourceEncoding [String] | The encoding format used for handling source files within the project. |
| javaVersion [String] | Specifies the Java version used to compile and run the project. By default, this is the same as the version used to run Jeka. |
| pack.jarType [enum:JkProjectPackaging$JarType] | Type of jar to produce for the main artifact. |
| pack.shadeJarClassifier [String] | If not blank, the project will produce an extra shade jar having the specified classifier name. A shade Jar embeds classes coming from dependency jars. The dependency class packages are relocated to avoid potential collisions with other jar present in the classpath. |
| pack.mainClass [String] | Main class name to include in Manifest. |
| pack.detectMainClass [boolean] | If true and no mainClass specified, it will be detected and added to the Manifest. |
| pack.javadocOptions [String] | Options to pass to javadoc tool when invoked. e.g '--notimestamp -doctitle "My Project API"'. |
| run.jvmOptions [String] | JVM options to use when running generated jar. |
| run.programArgs [String] | Program arguments to use when running generated jar. |
| run.useRuntimeDepsForClasspath [boolean] | If true, the resolved runbase classpath will be used when running the generated jar. If the generated jar is a Uber jar or contains all the needed dependencies, leave it to 'false'. |
| dependencies.compile [String] | Comma separated compile dependencies to include at scaffold time. |
| dependencies.runtime [String] | Comma separated runtime dependencies to include at scaffold time. |
| dependencies.test [String] | Comma separated test dependencies to include at scaffold time. |
| test.includePatterns [String] | Space-separated string to filter the test class names to run. Use regex patterns like '.', '.Test', '.*IT', or 'ac.me.MyTest'. |
| test.skip [boolean] | If true, tests are not run. |
| test.fork [boolean] | If true, tests will be executed in a forked process. |
| test.jvmOptions [String] | Argument passed to the JVM if tests are executed in a forked process (example -Xms2G -Xmx2G). |
| test.progress [enum:JkTestProcessor$JkProgressStyle] | The style to use to show test execution progress. |
| scaffold.generateLibsFolders [boolean] | Generate libs sub-folders for hosting local libraries. |
| scaffold.kind [enum:JkProjectScaffold$Kind] | The template used for scaffolding the build class. |
| scaffold.jekaVersion [String] | Set a specific jeka.version to include in jeka.properties. NO: no jeka.version specified, [EMPTY]: last version found in Maven Central. |
| scaffold.jekaLocation [String] | Set a specific jeka.distrib.location to include in jeka.properties. |
| scaffold.jekaDistribRepo [String] | Set a specific jeka.distrib.repo to include in jeka.properties. |
| scaffold.extraJekaProps [String] | Coma separated string representing properties to add to jeka.properties. |
| scaffold.rawJekaPropsContentPath [Path] | Set the path of a file containing the exact content of the jeka.properties file to generate. If this field is set, all others related to jeka.properties generation are ignored. |
| layout.style [enum:JkCompileLayout$Style] | Style of directory source structure (src/main/java or just src). |
| layout.mixSourcesAndResources [boolean] | If true, Resource files are located in same folder than Java code. |
| compilation.fork [boolean] | Specify whether to fork the compilation process. |
| compilation.javaVersion [String] | The target JVM version for compiled files. |
| compilation.compilerOptions [String] | Extra arguments to be passed to the compiler (example -Xlint:unchecked). |
| outputFile [Path] | The output file for the xml dependency description. |
| gitVersioning.enable [boolean] | If true, a version computed from the current Git branch/tag will be injected into the Maven KBean to determine the published version. |
| gitVersioning.tagPrefix [String] | Some prefer to prefix version tags like 'v1.3.1' instead of simply using '1.3.1'. In such cases, this value can be set to 'v' or any other chosen prefix. |
This KBean exposes the following methods:
| Method | Description |
|---|---|
| build | Runs a full build: cleans, compiles, tests, packs, checks quality and runs end-to-end tests. |
| checkQuality | Runs the quality checkers. |
| clean | Deletes the content of jeka-output directory and might execute extra clean actions. |
| compile | Performs compilation and resource processing. |
| depTree | Displays resolved dependency trees on console. |
| depTreeAsXml | Displays resolved dependency trees as xml, on console. |
| e2eTest | Runs the registered end-to-end tests. |
| generateSources | Generates sources. |
| info | Displays information about the Java project to build. |
| pack | Generates artifacts based on 'pack' options. Creates a single JAR by default. |
| runJar | Runs the generated jar. |
| runMain | Runs the compiled classes. |
| scaffold | Scaffolds a JeKa project skeleton in working directory. |
| test | Compiles and run tests defined within the project (typically Junit tests). |