Extending ArchUnit with Nebula ArchRules
Key point
Netflix introduced a way to share ArchUnit rules across tens of thousands of Java repos using Nebula ArchRules.
Details
Netflix built Nebula ArchRules to consistently apply common build logic and API usage rules across a polyrepo environment with tens of thousands of Java repos. The starting point was a backward compatibility problem that arose when deprecated code was removed from an older library, which prompted them to organize an API lifecycle system distinguishing @Deprecated, @Public, @Experimental, and treating everything else as internal.
The reasons for choosing ArchUnit are clear.
- Being based on ASM/bytecode, it applies across the entire JVM language ecosystem, including Kotlin and Scala.
- Thanks to its fluent builder API, rules can be written and tested easily as type-safe Java code.
- It can also look at class relationships and call sites, enabling more complex static analysis rules.
The library plugin of Nebula ArchRules adds Gradle's archRules source set and has ArchRulesService return a Map<String, ArchRule>. Rules are packaged as a separate JAR and distributed downstream through a variant with the usage attribute set to arch-rules and Gradle Module Metadata.
Operation is split into two approaches. Standalone rule libraries are shared rules applied to all source sets, while bundled rule libraries are distributed together with the main code and automatically applied only to source sets that use that library. The runner plugin creates a configuration per source set, merges the archRules classpath with the runtimeClasspath, discovers rules via ServiceLoader, and evaluates them with archRuleRuntime-level classpath isolation and a Work Action.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.