{"record":{"id":"3af70f864b10f67c","repo":"gradle/gradle","slug":"the-rule-source-provided-does-not-provide-a-valid","errorCode":null,"errorMessage":"The rule source provided does not provide a valid rule for '%s'.","messagePattern":"The rule source provided does not provide a valid rule for '(.+?)'\\.","errorType":"validation","errorClass":"InvalidUserCodeException","httpStatus":null,"severity":"error","filePath":"platforms/software/dependency-management/src/main/java/org/gradle/internal/rules/DefaultRuleActionAdapter.java","lineNumber":64,"sourceCode":"        }\n    }\n\n    @Override\n    public <T> RuleAction<? super T> createFromAction(Action<? super T> action) {\n        try {\n            return ruleActionValidator.validate(new NoInputsRuleAction<>(action));\n        } catch (RuleActionValidationException e) {\n            throw new InvalidUserCodeException(String.format(INVALID_ACTION_ERROR, context), e);\n        }\n    }\n\n    @Override\n    @Deprecated\n    public <T> RuleAction<? super T> createFromRuleSource(Class<T> subjectType, Object ruleSource) {\n        try {\n            return ruleActionValidator.validate(RuleSourceBackedRuleAction.create(ModelType.of(subjectType), ruleSource));\n        } catch (RuleActionValidationException e) {\n            throw new InvalidUserCodeException(String.format(INVALID_RULE_SOURCE_ERROR, context), e);\n        }\n    }\n}\n","sourceCodeStart":46,"sourceCodeEnd":68,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/software/dependency-management/src/main/java/org/gradle/internal/rules/DefaultRuleActionAdapter.java#L46-L68","documentation":"The deprecated RuleSource path: createFromRuleSource builds a RuleSourceBackedRuleAction from a class with @Rule-annotated methods and validates it. Any validation failure (missing/incorrect rule annotations, bad subject or parameter types) is wrapped as InvalidUserCodeException — 'The rule source provided does not provide a valid rule for <context>'. RuleSource is part of the removed software model, so builds still using it are on legacy ground.","triggerScenarios":"Calling a rule container API with a @RuleSource-annotated class whose methods do not conform to what RuleSourceBackedRuleAction.create expects for the given subject type.","commonSituations":"Maintaining pre-software-model-removal plugins; porting old samples; Gradle upgrades that tightened or removed RuleSource support.","solutions":["Migrate off @RuleSource entirely — rewrite the rule as a plain closure/Action rule or modern configuration APIs","Ensure exactly one @Rule method with the correct subject and input parameter annotations for the target container","Pin the last Gradle version supporting your RuleSource plugin while migrating"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import org.gradle.model.Rule\n// sanity-check a RuleSource before registration: exactly one @Rule method,\n// first parameter = expected subject type\nstatic boolean looksLikeValidRuleSource(Class<?> ruleSource, Class<?> subject) {\n    def ruleMethods = ruleSource.declaredMethods.findAll { it.isAnnotationPresent(Rule) }\n    ruleMethods.size() == 1 && ruleMethods[0].parameterTypes.length > 0 &&\n        ruleMethods[0].parameterTypes[0].isAssignableFrom(subject)\n}","typeGuard":null,"tryCatchPattern":"try {\n    adapter.createFromRuleSource(subjectType, ruleSourceInstance)\n} catch (org.gradle.api.InvalidUserCodeException e) {\n    throw new GradleException('RuleSource ' + ruleSourceInstance.class.name + ' does not provide a valid @Rule for ' + subjectType.simpleName, e)\n}","preventionTips":["Migrate away from @RuleSource — it belongs to the removed software model","Annotate exactly one @Rule method with the correct subject parameter","Keep legacy RuleSource plugins pinned to Gradle versions that support them"],"tags":["gradle","rules","rule-source","deprecated","legacy-software-model"],"backgroundTag":"invalid-rule-source","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}