Usage Guide

The recommended way to run CODERU is as a JUnit test using CoderuVerifier. It works with any build tool, produces named test failures in CI reports, and scales naturally as you add more focused checks.

Add the dependency

Add coderu-junit-adapter as a test dependency. It pulls in coderu-core transitively.

<dependency>
    <groupId>org.coderu</groupId>
    <artifactId>coderu-junit-adapter</artifactId>
    <version>1.2.16</version>
    <scope>test</scope>
</dependency>

Basic check

Create a JUnit test class, provide an anchor class from your project so CODERU can locate the compiled bytecode, set the root package with includingPackages(), and call run(). The test fails if any rule is violated.

This is the right starting point for a new project. It checks the entire org.coderu.example tree and detects all six violations.

import org.coderu.CoderuVerifier;
import org.junit.jupiter.api.Test;

class CoderuTest {

    @Test
    void checkAll() {
        CoderuVerifier
            .ofLocatedBy(AnyClassInYourProject.class)
            .includingPackages("org.coderu.example")
            .run();
    }
}

Test failure output:

Example project

All examples below refer to a sample project with the following package structure. It contains six intentional CODERU violations (shown as red arcs in the diagram).

Example project package structure with violations

The table below lists each forbidden dependency and explains which CODERU rule it violates.

# Dependency Violated rule Why it is forbidden
1 common → gui.common Basic Rule common and gui are siblings under org.coderu.example. A module may only depend on its own sub-modules, not on sub-modules of a sibling.
2 common.collections → common.logging Basic Rule collections and logging are siblings inside common. Sibling-to-sibling access is forbidden by the Basic Rule.
3 gui.common.formbase → gui.common Basic Rule A sub-module must not access its own parent module. The Basic Rule only grants access downward (parent → child), never upward (child → parent).
4 gui.users → business.users Basic Rule gui and business are top-level sibling modules. Neither may access the other or any of its sub-modules without an explicit api package.
5 business.api → business.orders API Rule An api package must not access sibling non-api packages. The api package is intended as a stable public interface; reaching into a sibling implementation package breaks that boundary. Note: CODERU does not prevent cycles between api packages — those remain the developer's responsibility.
6 business.orders → gui.common Basic Rule The business layer must not depend on the GUI layer. gui.common being a common-named package only grants access to siblings within gui, not to modules in other top-level branches like business.

Only dependencies within the checked root package are analysed. References to external libraries are ignored.

Partial check — bottom-up strategy

For an existing project not built with CODERU from the start, checking everything at once is impractical. Pass multiple package names to includingPackages() to limit the check to specific subtrees and clean up the codebase incrementally.

The test below restricts the check to org.coderu.example.common and org.coderu.example.gui.common (and their descendants), exposing three of the six violations.

@Test
void checkBottomUp() {
    CoderuVerifier
        .ofLocatedBy(AnyClassInYourProject.class)
        .includingPackages(
            "org.coderu.example.common",
            "org.coderu.example.gui.common"
        )
        .run();
}

Test failure output:

Partial check — top-down strategy

Use withMaxPackageDepth(n) to limit how deep in the hierarchy the check is applied. Start with a shallow depth and gradually increase it as you fix violations level by level.

With depth 4 the check covers packages up to org(1) . coderu(2) . example(3) . {common,gui,business}(4). Violations inside sub-packages below that level are not reported.

@Test
void checkTopDown() {
    CoderuVerifier
        .ofLocatedBy(AnyClassInYourProject.class)
        .includingPackages("org.coderu.example")
        .withMaxPackageDepth(4)
        .run();
}

Test failure output:

Exclude packages

Use excludingPackages() to whitelist packages that are not yet compliant and should be skipped. Combine with either strategy above to isolate the check to the parts of the codebase you are ready to fix.

Excluding common.logging and gui.common removes four of the six violations, leaving only the two cross-module dependencies that do not touch the excluded packages.

@Test
void checkWithExclusions() {
    CoderuVerifier
        .ofLocatedBy(AnyClassInYourProject.class)
        .includingPackages("org.coderu.example")
        .excludingPackages(
            "org.coderu.example.common.logging",
            "org.coderu.example.gui.common"
        )
        .run();
}

Test failure output:

Check inter-package references

CODERU's natural mode treats every class as a module of its own: classes within the same package are considered siblings, and references between them are checked just like references between sibling packages — nothing is granted for free just because two classes share a package name. In this strict mode a dependency from gui.common.FormBase to gui.common.FormBaseHelper is evaluated as a sibling-to-sibling reference and is prohibited by CODERU's rules.

This mode is disabled by default purely for convenience and easier adoption: most existing codebases rely heavily on intra-package co-location, so allowing free references within a package lets teams introduce CODERU incrementally without having to restructure everything at once. Once inter-package boundaries are clean you can opt in to the stricter check and remove the last remaining clusters of tightly coupled classes.

@Test
void checkInterPackageReferences() {
    CoderuVerifier
        .ofLocatedBy(AnyClassInYourProject.class)
        .includingPackages("org.coderu.example")
        .allowIntraPackageDependencies(false)
        .run();
}

Use synonyms

If your project already uses different naming conventions, remap each CODERU reserved name to a custom synonym using packageNaming(). The four names must be provided in order via the step-builder: api → impl → common → factory.

CODERU defaultExample synonym
apipublic_
implprivate_
commonshared
factorybuilder
import org.coderu.CoderuVerifier;
import org.coderu.impl.PackageNaming;

@Test
void checkWithSynonyms() {
    CoderuVerifier
        .ofLocatedBy(AnyClassInYourProject.class)
        .includingPackages("org.coderu.example")
        .packageNaming(
            PackageNaming.api("public_")
                         .impl("private_")
                         .common("shared")
                         .factory("builder")
        )
        .run();
}

When synonyms are active, only packages matching the custom names carry special semantics. Packages named api, impl, etc. are treated as ordinary packages and the Basic Rule applies to them instead.

Maven plugin alternative

If you prefer zero test code, CODERU also ships as a Maven plugin that hooks into the test phase automatically.

<plugin>
    <groupId>org.coderu</groupId>
    <artifactId>coderu-maven-plugin</artifactId>
    <version>1.2.16</version>
    <executions>
        <execution>
            <id>coderu</id>
            <goals><goal>test</goal></goals>
        </execution>
    </executions>
</plugin>

The plugin accepts the same options (rootPackages, depth, excludedPackages, classesDependencyInPackageAllowed, and synonym tags) via the standard <configuration> block. For green-field projects where CODERU is introduced from day one, the Maven plugin offers a zero-code alternative worth considering. For everything else — incremental adoption, fine-grained checks, or mixed strategies — the JUnit approach is recommended: it gives full control over every option and integrates naturally with the rest of your test suite.