@@ -29,37 +29,33 @@ public class GradleTaskActionRule implements ArchRulesService {
2929 * cause runtime errors in Gradle 10+. Move Project access to configuration time
3030 * (constructor/initializer) and use task properties instead.
3131 */
32- public static final ArchRule taskActionShouldNotAccessProject = createTaskActionRule (
33- notAccessProject (),
34- "access the Project object" ,
35- "Accessing Project in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
36- "Move Project access to task configuration time and use task inputs/properties instead." ,
37- "task_project"
38- );
32+ public static final ArchRule taskActionShouldNotAccessProject = ArchRuleDefinition .priority (Priority .MEDIUM )
33+ .methods ()
34+ .that (areAnnotatedWithTaskAction ())
35+ .should (notAccessProject ())
36+ .allowEmptyShould (true )
37+ .because (
38+ "Accessing Project in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
39+ "Move Project access to task configuration time and use task inputs/properties instead. " +
40+ "See https://docs.gradle.org/9.2.0/userguide/upgrading_version_7.html#task_project"
41+ );
3942
4043 /**
4144 * Prevents {@code @TaskAction} methods from calling {@code getTaskDependencies()}.
4245 * <p>
4346 * Calling {@code getTaskDependencies()} in task actions breaks configuration cache and will
4447 * cause runtime errors in Gradle 10+. Task dependencies should be declared at configuration time.
4548 */
46- public static final ArchRule taskActionShouldNotCallGetTaskDependencies = createTaskActionRule (
47- notCallGetTaskDependencies (),
48- "call getTaskDependencies()" ,
49- "Calling getTaskDependencies() in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
50- "Declare task dependencies at configuration time instead." ,
51- "task_dependencies"
52- );
53-
54- private static ArchRule createTaskActionRule (ArchCondition <JavaMethod > condition , String actionDescription , String reason , String docAnchor ) {
55- return ArchRuleDefinition .priority (Priority .MEDIUM )
56- .methods ()
57- .that (areAnnotatedWithTaskAction ())
58- .should (condition )
59- .allowEmptyShould (true )
60- .as ("Methods annotated with @TaskAction should not " + actionDescription )
61- .because (reason + " See https://docs.gradle.org/9.2.0/userguide/upgrading_version_7.html#" + docAnchor );
62- }
49+ public static final ArchRule taskActionShouldNotCallGetTaskDependencies = ArchRuleDefinition .priority (Priority .MEDIUM )
50+ .methods ()
51+ .that (areAnnotatedWithTaskAction ())
52+ .should (notCallGetTaskDependencies ())
53+ .allowEmptyShould (true )
54+ .because (
55+ "Calling getTaskDependencies() in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
56+ "Declare task dependencies at configuration time instead. " +
57+ "See https://docs.gradle.org/9.2.0/userguide/upgrading_version_7.html#task_dependencies"
58+ );
6359
6460 private static DescribedPredicate <JavaMethod > areAnnotatedWithTaskAction () {
6561 return new DescribedPredicate <JavaMethod >("are annotated with @TaskAction" ) {
0 commit comments