11/*
2- * Copyright 2012-2024 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
6969import org .gradle .api .tasks .SkipWhenEmpty ;
7070import org .gradle .api .tasks .TaskAction ;
7171
72+ import org .springframework .beans .factory .config .BeanDefinition ;
73+ import org .springframework .context .annotation .Role ;
7274import org .springframework .util .ResourceUtils ;
7375
7476/**
@@ -149,7 +151,8 @@ private ArchCondition<JavaMethod> onlyHaveParametersThatWillNotCauseEagerInitial
149151 DescribedPredicate <JavaClass > notOfASafeType = DescribedPredicate
150152 .not (Predicates .assignableTo ("org.springframework.beans.factory.ObjectProvider" )
151153 .or (Predicates .assignableTo ("org.springframework.context.ApplicationContext" ))
152- .or (Predicates .assignableTo ("org.springframework.core.env.Environment" )));
154+ .or (Predicates .assignableTo ("org.springframework.core.env.Environment" )
155+ .or (annotatedWithRoleInfrastructure ())));
153156 return new ArchCondition <>("not have parameters that will cause eager initialization" ) {
154157
155158 @ Override
@@ -167,6 +170,18 @@ public void check(JavaMethod item, ConditionEvents events) {
167170 };
168171 }
169172
173+ private DescribedPredicate <JavaClass > annotatedWithRoleInfrastructure () {
174+ return new DescribedPredicate <>("annotated with @Role(BeanDefinition.ROLE_INFRASTRUCTURE" ) {
175+
176+ @ Override
177+ public boolean test (JavaClass candidate ) {
178+ Role role = candidate .getAnnotationOfType (Role .class );
179+ return (role != null ) && (role .value () == BeanDefinition .ROLE_INFRASTRUCTURE );
180+ }
181+
182+ };
183+ }
184+
170185 private ArchRule allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters () {
171186 return ArchRuleDefinition .methods ()
172187 .that ()
0 commit comments