diff --git a/src/main/groovy/com/netflix/nebula/lint/rule/GradleLintRule.groovy b/src/main/groovy/com/netflix/nebula/lint/rule/GradleLintRule.groovy index 7386b6d2..6fa4392f 100644 --- a/src/main/groovy/com/netflix/nebula/lint/rule/GradleLintRule.groovy +++ b/src/main/groovy/com/netflix/nebula/lint/rule/GradleLintRule.groovy @@ -426,7 +426,8 @@ abstract class GradleLintRule extends GroovyAstVisitor implements Rule { return null } dependency = GradleDependency.fromConstant(expr) - } else if (call.arguments.expressions.any { it instanceof PropertyExpression } && project != null) { + } else if ((configurationWithArbitraryProperty(call) || configurationWithArbitraryMethodCall(call) ) + && project != null) { Object dep def shell = new GroovyShell() shell.setVariable('project', project as Project) @@ -468,6 +469,16 @@ abstract class GradleLintRule extends GroovyAstVisitor implements Rule { } } + //e.g. implementation sourceSets.main.output + private boolean configurationWithArbitraryProperty(MethodCallExpression call) { + call.arguments.expressions.any { it instanceof PropertyExpression } + } + + //e.g. implementation fileTree(..) + private boolean configurationWithArbitraryMethodCall(MethodCallExpression call) { + call.arguments.expressions.any { it instanceof MethodCallExpression && it.methodAsString != 'project'} + } + private void visitMethodCallInPlugins(MethodCallExpression call) { // https://docs.gradle.org/current/javadoc/org/gradle/plugin/use/PluginDependenciesSpec.html def args = call.arguments.expressions as List diff --git a/src/test/groovy/com/netflix/nebula/lint/rule/GradleLintRuleSpec.groovy b/src/test/groovy/com/netflix/nebula/lint/rule/GradleLintRuleSpec.groovy index 36170d75..af404f64 100644 --- a/src/test/groovy/com/netflix/nebula/lint/rule/GradleLintRuleSpec.groovy +++ b/src/test/groovy/com/netflix/nebula/lint/rule/GradleLintRuleSpec.groovy @@ -301,6 +301,7 @@ class GradleLintRuleSpec extends AbstractRuleSpec { project.buildFile << """ dependencies { customConfig sourceSets.main.output + customConfig fileTree('dir') customConfig configurations.compile } """ @@ -310,7 +311,7 @@ class GradleLintRuleSpec extends AbstractRuleSpec { then: rule.allGradleDependencies.size() == 1 - rule.objectDependencies.size() == 1 + rule.objectDependencies.size() == 2 } def 'visit dependencies in a project path project block'() {