Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

transitive — transitive module readability

During module resolution, `requires transitive` makes modules that read the declaring module also read the specified dependency. A read edge added later with `Module.addReads` does not automatically extend to the target module’s transitive dependencies. `exports` and access-control rules still apply.

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

requires transitive ModuleName;

transitive is a Java SE 21 contextual keyword used as a requires modifier in a module declaration, normally in module-info.java. It is not globally reserved: outside the relevant context, it can be an identifier.

If demo.app declares requires demo.bridge; and demo.bridge declares requires transitive java.logging;, then module resolution makes demo.app read java.logging as well. Ordinary requires java.logging; in demo.bridge does not provide this transitive readability.

Readability does not export packages: exports and access-control rules still apply. Use transitive when consumers of a module's API need types from its dependency. Do not confuse it with static, which makes a dependency mandatory at compile time but optional at run time; both modifiers can be combined as requires static transitive ModuleName;.

Examples

// src/demo.bridge/module-info.java
module demo.bridge {
    requires transitive java.logging;
}

// src/demo.app/module-info.java
module demo.app {
    requires demo.bridge;
}

// src/demo.app/demo/app/Main.java
package demo.app;

import java.util.logging.Logger;

public class Main {
    public static void main(String[] args) {
        Logger logger = null;
        System.out.println(logger == null);
    }
}

Result

true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources