@@ -34,6 +34,39 @@ public class LibraryClass {
3434 """
3535 )
3636 }
37+ sourceSet(" archRules" ) {
38+ java(
39+ " com/example/library/LibraryArchRules.java" ,
40+ // language=java
41+ """
42+ package com.example.library;
43+
44+ import com.netflix.nebula.archrules.core.ArchRulesService;
45+ import com.tngtech.archunit.lang.Priority;
46+ import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
47+
48+ import static com.tngtech.archunit.core.domain.JavaAccess.Predicates.target;
49+ import static com.tngtech.archunit.core.domain.JavaAccess.Predicates.targetOwner;
50+ import static com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith;
51+
52+ public class LibraryArchRules implements ArchRulesService {
53+ private final ArchRule noDeprecated = ArchRuleDefinition.priority(Priority.LOW)
54+ .noClasses()
55+ .should().accessTargetWhere(targetOwner(annotatedWith(Deprecated.class)))
56+ .orShould().accessTargetWhere(target(annotatedWith(Deprecated.class)))
57+ .orShould().dependOnClassesThat().areAnnotatedWith(Deprecated.class)
58+ .allowEmptyShould(true)
59+ .as("No code should reference deprecated APIs")
60+ .because("usage of deprecated APIs introduces risk that future upgrades and migrations will be blocked");
61+
62+ @Override
63+ public Map<String, ArchRule> getRules() {
64+ return Map.of("deprecated", noDeprecated);
65+ }
66+ }
67+ """
68+ )
69+ }
3770 }
3871 }
3972 subProject(" code-to-check" ) {
@@ -48,8 +81,11 @@ public class LibraryClass {
4881 }
4982 }
5083
51- val result = runner.run (" check" )
84+ val result = runner.run (" check" , " compileArchRulesJava " )
5285
86+ assertThat(result.task(" :library-with-rules:compileArchRulesJava" ))
87+ .`as `(" compile task runs for the archRules source set" )
88+ .hasOutcome(TaskOutcome .SUCCESS , TaskOutcome .UP_TO_DATE )
5389 assertThat(result.task(" :library-with-rules:check" ))
5490 .hasOutcome(TaskOutcome .SUCCESS , TaskOutcome .UP_TO_DATE )
5591 assertThat(result.task(" :code-to-check:check" ))
0 commit comments