Skip to content

Project KBean

Manages the build and execution of a JVM projects.

It contains all information 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.
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. Use 'auto' to automatic discovering.
pack.detectMainClass [boolean] If true and no mainClass specified, it will be detected and added to the Manifest.
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.
tests.includePatterns [String] Space-separated string to filter the test class names to run. Use regex patterns like '.', '.Test', '.*IT', or 'ac.me.MyTest'.
tests.skip [boolean] If true, tests are not run.
tests.fork [boolean] If true, tests will be executed in a forked process.
tests.jvmOptions [String] Argument passed to the JVM if tests are executed in a forked process (example -Xms2G -Xmx2G).
tests.progress [enum:JkTestProcessor$JkProgressStyle] The style to use to show test execution progress.
tests.platformVersion [String] The junit-platform to use. If empty, the default version will be used (1.9.3).
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
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 from scratch artifacts defined through 'pack' options if not yet generated. Use #cleanPack to force re-generation.
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).

ProjectKBean acts as a wrapper around a JkProject to facilitate the building of JVM-based code hosted in a project structure. This KBean provides core methods for fundamental build tasks, including compiling, testing, and packaging.

To work effectively with this KBean, it's helpful to have an overview of the capabilities offered by the JkProject object.

Key Features

  • Resolves dependencies, compiles code, and runs tests.
  • Creates various types of JAR files out-of-the-box, including regular, fat, shaded, source, and Javadoc JARs.
  • Infers project versions from Git metadata.
  • Executes packaged JARs.
  • Displays dependency trees and project setups.
  • Scaffolds skeletons for new projects.

Additionally, ProjectKBean serves as a central point of interaction for other KBeans, enabling them to access project details and extend or enhance the build process.

It offers standardized methods that cover the whole build life-cycle:

  • scaffold: Creates new project structure from scratch
  • generateSources: Generates source code
  • compile: Compiles source code
  • test: Compiles and run test code
  • pack: Creates packaged artifacts as JAR files
  • checkQuality: Runs quality checkers and quality gates
  • e2eTest: Runs end-to-end test on a deployed version of the application

The JkProject instance offers methods to customize or extend behavior, allowing seamless integration of third-party extensions.

Example for getting information about source files:

class MyBuild extends KBean {

  private List<Path> allSourceFiles;

  @JkPostInit
  private void postInit(ProjectKBean projectKBean) {
      allSourceFiles = projectKBean.project.compilation.layout.resolveSources().getFiles();
      ...
  }
}

Example taken from JeKa:

  • Jacoco KBean: A KBean that reads te underlying JkProject and modifies its testing behavior.
  • Sonarqube KBean: A KBean that reads te underlying JkProject to extract information.
  • Protobuf KBean: A KBean that adds a Proto-buffer code generation to the underlying JkProject.