Building Java Integration Projects
Klok Java integration projects are template-based Gradle projects using the Klok Gradle Plugin and Klok Quarkus Extension. Developers should focus on route behavior, not on assembling platform mechanics from scratch.
Project Layers
| Layer | Responsibility |
|---|---|
| Integration template | Starter structure, Gradle wrapper, standard files, examples, and directories |
| Klok Gradle Plugin | Versioning, dependency management, standard dependencies, publishing, and release logic |
| Klok Quarkus Extension | Runtime conventions on top of Quarkus and Apache Camel, route patterns, logging, and broker integration |
| Project routes | Ingress, egress, processing, custom, bridge, and adapter code written for the solution |
Template Generation
When the admin app creates a project, it should clone the integration template, rename the template remote, add the target GitLab project as origin, write project-specific metadata and routes, commit, push, and create a documentation project.
The GUI should not hardcode build.gradle content or let users choose an arbitrary build system. The build foundation
comes from the template and plugin.
Dependencies Come From Two Catalogs
Versions are never typed into build.gradle. A project reads two Gradle version catalogs, and every pipeline refreshes
both copies with ./gradlew updateKlokLibsToml before it builds, so a build always has the latest versions:
| Catalog | Refreshed into | Holds |
|---|---|---|
klokLibs |
gradle/klok-libs.versions.toml |
the Klok Gradle plugin, the framework, aligned third-party versions, the bundles, and klok's datamodels (the public platform catalog) |
tenantLibs |
gradle/tenant-libs.versions.toml |
your tenant's own datamodels and libraries (the tenant's private catalog, <tenant>/framework/<tenant>-gradle-dependency-catalog; empty for tenant klok) |
A platform datamodel is implementation klokLibs.<alias>, one of your tenant's implementation tenantLibs.<alias>. The
tenant catalog also carries the tenant's generated agent skills, which ./gradlew updateKlokAgents and klok agents update install next to the platform skills.
Klok's Files In Your Repository
The rules for coding agents (KLOK-AGENTS.md, the klok-* skills, knowledge/) and the two catalog copies are Klok's,
and nobody has to remember them:
- Everything comes from one public catalog.
- Pipelines always build with the latest versions.
- A Klok job keeps these files in every repository current, once a week, with a commit of its own that starts no pipeline
and redeploys nothing.
git pullbrings them. Do not edit or commit them yourself. klok fleet statusshows what is behind.klok fleet upgradeandklok fleet rebuildbring it current when you say so. A running service is never upgraded by itself.
The one exception: when your change needs a version or an alias the committed copy lacks, such as a datamodel released
this week, run ./gradlew updateKlokLibsToml and commit the changed catalog copy with your change, because a build
script cannot be configured without the alias. A conflict in that file is solved by taking main's and running the task
again. A project with a reason to stay where it is opts out with the GitLab topic klok-no-upgrade.
What Developers Usually Implement
Developers normally add:
- Data model dependencies.
- Reads and writes of datamodel objects in the Operative Data Layer (see Using Datamodels In The ODL).
- Route classes.
- Transformation logic.
- Extra Camel components when a special protocol is required.
- External Java libraries when not already supplied by the standard framework.
- Unit and integration tests.
Onramp Example Shape
public class ACME001I1_UserImportOnramp extends KlokOnrampRoute<SystemUser, UserV1> {
@Override
public UserV1 transformBody(SystemUser body, Message message, Exchange exchange) {
UserV1 user = new UserV1();
user.setUserId(body.getId());
user.setDisplayName(body.getName());
return user;
}
}
The framework should handle standard broker connection, CloudEvent envelope behavior, logging, and failure handling. The example focuses on transformation.
Offramp Example Shape
public class ACME001E1_UserExportOfframp extends KlokOfframpRoute<UserV1, SystemUser> {
@Override
public SystemUser transformBody(UserV1 body, Message message, Exchange exchange) {
SystemUser user = new SystemUser();
user.setId(body.getUserId());
user.setName(body.getDisplayName());
return user;
}
@Override
protected String toUri() {
return "direct:target-system";
}
}
Framework Responsibilities
The framework patterns normally handle:
- Pulsar connectivity.
- CloudEvent wrapping.
- Standard serialization and deserialization.
- Start, success, and failure logging.
- Retry behavior.
- DLQ routing.
- Tracing hooks.
- Documentation and context metadata extraction.
Developer Responsibilities
The developer still owns:
- Correct mapping between models.
- Source and target endpoint choices.
- Handling business validation.
- Tests that cover normal and failure cases.
- Avoiding secret leakage.
- Keeping route IDs and class names aligned with the solution.
- Agreeing on the topic purpose with the project on the other end of a topic, when a datamodel is used in more than one flow (see Topic Purpose).