UnsupportedOperationException in DefaultModuleResolutionFilter

issue-acknowledged
gradle-3275

(PJ Fanning) #1

Hi,
Would it be possible to make these exceptions in the intersect methods of DefaultModuleResolutionFilter$ExcludeRuleBackedSpec include module names or other dependency details that would make it easier to see which dependency exclusion is causing the issue?
This issue is happening in line 387 in gradle 2.3 codebase.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:dependencies’.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:306)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:56)
    Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ‘:default’.
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.wrapException(ErrorHandlingArtifactDependencyResolver.java:61)
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:49)
    at org.gradle.api.internal.artifacts.ivyservice.DefaultConfigurationResolver.resolve(DefaultConfigurationResolver.java:46)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveNow(DefaultConfiguration.java:250)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.access$800(DefaultConfiguration.java:46)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationResolvableDependencies.getResolutionResult(DefaultConfiguration.java:547)
    at org.gradle.api.tasks.diagnostics.internal.dependencies.AsciiDependencyReportRenderer.render(AsciiDependencyReportRenderer.java:82)
    at org.gradle.api.tasks.diagnostics.DependencyReportTask.generate(DependencyReportTask.java:58)
    at org.gradle.api.tasks.diagnostics.AbstractReportTask.generate(AbstractReportTask.java:80)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:585)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:568)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    … 47 more
    Caused by: java.lang.UnsupportedOperationException
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultModuleResolutionFilter$ExcludeRuleBackedSpec.intersect(DefaultModuleResolutionFilter.java:387)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultModuleResolutionFilter$ExcludeRuleBackedSpec.doUnion(DefaultModuleResolutionFilter.java:358)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultModuleResolutionFilter.union(DefaultModuleResolutionFilter.java:93)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder$ConfigurationNode.getSelector(DependencyGraphBuilder.java:767)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder$ConfigurationNode.visitOutgoingDependencies(DependencyGraphBuilder.java:713)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder.traverseGraph(DependencyGraphBuilder.java:109)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder.resolveDependencyGraph(DependencyGraphBuilder.java:90)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:80)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:122)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:88)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:137)
    at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:61)
    at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:39)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:88)
    at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.run(CacheLockingArtifactDependencyResolver.java:42)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192)
    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
    at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187)
    at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:64)
    at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:40)
    at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:45)
    at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyResolver.java:55)
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:47)
    … 62 more

(Luke Daley) #2

@DazDeBoer anything easy we can do here?


#3

In theory, this should never happen. But we’ve recently added new subtypes of DefaultModuleResolutionFilter, and I can see how this could happen.

For now, I’ve added more context to the error message. The correct fix is to enable intersection for DefaultModuleResolutionFilter.ArtifactSpec, or to avoid intersection for these.

Would you be interested in contributing a fix?


(PJ Fanning) #4

I was able to track down the dependencies that caused the issue and set transitive=false to work around the issue. I was going to attach the ivy.xml from one of the dependencies but as a new user, I don’t have permissions.
One of the transitive dependencies in this ivy.xml is:

<dependency org="com.acme" name="zookeeper" rev="+" conf="testCompile->default">
    <artifact name="zookeeper-test" type="jar" ext="jar" conf="" m:classifier="-test"/>
</dependency>

Is this the kind of entry that could lead to the exception?
If necessary, I can email a slightly obfuscated version of the ivy.xml.


#5

I’m expecting to see an exclude rule to cause this: are there excludes defined in the ivy file?


(PJ Fanning) #6

Here are 2 samples from the ivy.xml:

<dependencies>
  <dependency org="org.apache.kafka" name="kafkawdpatch01" rev="2.10-0.8.0" conf="compile->default">
    <exclude org="org.apache.zookeeper" module="zookeeper" name="*" type="*" ext="*" conf="compile" matcher="exact"/>
  </dependency>

  <exclude org="com.google.code.findbugs" module="*" artifact="*" type="*" ext="*" conf="archives" matcher="exact"/>
</dependencies>

#7

Thanks @pjfanning
I’ve pushed a fix, as well as more descriptive error messages if it doesn’t work.
Once my change makes it through to a nightly build, it would be great if you could try it out. That should happen in the next few hours.

Daz


(PJ Fanning) #8

Thanks @DazDeBoer. I tried the nightly build with your changes (GRADLE-3275) and it still fails but the error message is much more informative. I have worked around this issue by not relying on transitive dependencies that have these unusual exclusion rules.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:api:api-dataservice:dependencies’.

Could not resolve all dependencies for configuration ‘:api:api-dataservice:compile’.
Cannot calculate intersection of exclude rules: {module-id cglib:cglib}, {UnionSpec {ExcludeRuleBackedSpec {module-id com.google.code.findbugs:cglib} {module-id cglib:cglib} {module-id org.codehaus.woodstox:paranamer} {module-id org.easymock:breeze-natives_2.10} {module-id org.codehaus.woodstox:tika-parsers} {module-id org.codehaus.woodstox:quasiquotes_2.10} {module-id com.google.code.findbugs:slf4j-simple} {module breeze-natives_2.10} {module-id org.apache.logging.log4j:paranamer} {module-id org.apache.logging.log4j:tika-parsers} {module-id org.apache.logging.log4j:quasiquotes_2.10} {module-id com.bea.xml:jsr173-ri} {module-id com.ibm.icu:cglib} {module-id com.ibm.icu:slf4j-simple} {module-id org.apache.logging.log4j:cglib} {module-id org.codehaus.woodstox:slf4j-simple} {module-id org.apache.logging.log4j:slf4j-simple} {module-id com.google.code.findbugs:quasiquotes_2.10} {module-id com.google.code.findbugs:tika-parsers} {module-id org.codehaus.woodstox:cglib} {module-id com.google.code.findbugs:paranamer} {module-id org.easymock:activation} {module jflex} {module-id com.ibm.icu:paranamer} {module-id com.ibm.icu:tika-parsers} {module-id com.ibm.icu:quasiquotes_2.10} {module activation} {module-id org.easymock:jflex} {module-id com.google.code.findbugs:activation} {module-id com.google.code.findbugs:jflex} {module-id org.apache.logging.log4j:breeze-natives_2.10} {module-id com.ibm.icu:activation} {module tika-parsers} {module quasiquotes_2.10} {module paranamer} {module-id com.ibm.icu:jflex} {group org.apache.logging.log4j} {module-id org.codehaus.woodstox:breeze-natives_2.10} {module-id org.easymock:tika-parsers} {module-id org.easymock:quasiquotes_2.10} {module-id org.easymock:paranamer} {module-id org.codehaus.woodstox:jflex} {module-id com.ibm.icu:breeze-natives_2.10} {module-id org.apache.logging.log4j:activation} {module-id org.codehaus.woodstox:activation} {module-id org.apache.logging.log4j:jflex} {module-id org.easymock:cglib} {module slf4j-simple} {module-id com.google.code.findbugs:breeze-natives_2.10} {module cglib} {module-id org.easymock:slf4j-simple} {module-id com.typesafe.sbt:sbt-pgp}} {ExcludeRuleBackedSpec {module breeze-natives_2.10} {module-id com.bea.xml:jsr173-ri} {exclude-rule org.slf4j:jcl-over-slf4j:. with matcher exactOrRegexp} {module quasiquotes_2.10} {module tika-parsers} {module paranamer} {group org.apache.logging.log4j} {module slf4j-simple} {exclude-rule com.google.guava:guava:. with matcher exactOrRegexp} {module jflex} {module cglib} {module activation} {module-id com.typesafe.sbt:sbt-pgp}} {ExcludeRuleBackedSpec {module breeze-natives_2.10} {module slf4j-simple} {module-id com.bea.xml:jsr173-ri} {module quasiquotes_2.10} {module tika-parsers} {module jflex} {module paranamer} {exclude-rule com.google.guava:guava:. with matcher exactOrRegexp} {module cglib} {group org.apache.logging.log4j} {module-id com.typesafe.sbt:sbt-pgp} {module activation}} {ExcludeRuleBackedSpec {exclude-rule org.bouncycastle:bcprov-jdk15:. with matcher exactOrRegexp} {exclude-rule org.bouncycastle:bcpg-jdk15:. with matcher exactOrRegexp} {exclude-rule logkit::.* with matcher exactOrRegexp} {exclude-rule jdom::.* with matcher exactOrRegexp} {exclude-rule junit:junit:. with matcher exactOrRegexp} {exclude-rule com.google.guava:guava:. with matcher exactOrRegexp} {UnionSpec {ExcludeRuleBackedSpec {module breeze-natives_2.10} {module slf4j-simple} {module-id com.bea.xml:jsr173-ri} {module tika-parsers} {module quasiquotes_2.10} {module paranamer} {module jflex} {module cglib} {group org.apache.logging.log4j} {module activation} {module-id com.typesafe.sbt:sbt-pgp}} {ExcludeRuleBackedSpec {module breeze-natives_2.10} {module slf4j-simple} {module-id com.bea.xml:jsr173-ri} {exclude-rule org.slf4j:jcl-over-slf4j:. with matcher exactOrRegexp} {module quasiquotes_2.10} {module tika-parsers} {module jflex} {module paranamer} {module cglib} {group org.apache.logging.log4j} {module-id com.typesafe.sbt:sbt-pgp} {module activation}}} {exclude-rule ant::.* with matcher exactOrRegexp} {exclude-rule org.slf4j:slf4j-log4j12:. with matcher exactOrRegexp} {exclude-rule xalan::.* with matcher exactOrRegexp} {exclude-rule xml-resolver::.* with matcher exactOrRegexp}}}


(Francois Ritaly) #9

I work with PJ and I’ve seen this UnsupportedOperationException error occur with at least with 3 different projects. A workaround consists in excluding the transitive dependencies but this isn’t always doable. It looks like the error happens when a dependency (an Ivy one here defines exclusion rules for its transitive dependencies).

Out of curiosity, I tested with older versions of Gradle as I noticed that the error happened with 2.3 but not with 1.6.

My tests show that the error doesn’t happen with Gradle 2.0, 2.1, 2.2 and 2.2.1. It occurs as of Gradle 2.3. So it looks like some kind of regression.

Should I open another ticket ? If so, what should I typically document ?

Edit: Another workaround (instead of skipping transitive dependencies) consists in reverting to Gradle 2.2.1


#10

I’ve reopened the issue in Jira. If you have a reproducible example (that fails with the latest nightly), then it would really help if you could start to selectively remove dependencies and excludes until you have a minimal example that recreates this problem.

That will make it easier to add a failing integration test, and thus a fix.


(Francois Ritaly) #11

I confirmed that the issue still exists in 2.4. I’m trying to insulate a test project which reproduces the bug


(Francois Ritaly) #12

I’ve had this error this morning after upgrading Gradle to 2.6 but I’m unable to interpret the error message.

Cannot calculate intersection of exclude rules: {module-id junit:junit}, {UnionSpec {ExcludeRuleBackedSpec {module-id com.acme:kmixmlclient-generated}} {ExcludeRuleBackedSpec {exclude-rule org.slf4j:jcl-over-slf4j:. with matcher exactOrRegexp} {exclude-rule com.google.guava:guava:. with matcher exactOrRegexp} {module-id com.acme:kmixmlclient-generated}} {ExcludeRuleBackedSpec {exclude-rule com.google.guava:guava:. with matcher exactOrRegexp} {module-id com.acme:kmixmlclient-generated}}}

Can you please shed some light about what is wrong with the dependencies and the exclusions ?


(Niklas Grossmann) #13

The issue still exists in 2.12, root cause seems to be that DefaultModuleResolutionFilter.ExcludeRuleBackedSpec.doUnion(DefaultModuleResolutionFilter other) does not handle the case when either this.excludeSpecs or other.excludeSpecs contains an UnionSpec. I was able to work around/fix the issue by adding || excludeSpec instanceof UnionSpec in doUnion(...):

// Can only merge exact match rules, so don't try if this or the other spec contains any other type of rule
for (DefaultModuleResolutionFilter excludeSpec : excludeSpecs) {
    if (excludeSpec instanceof ExcludeRuleSpec || excludeSpec instanceof UnionSpec) {
        return super.doUnion(other);
    }
}

for (DefaultModuleResolutionFilter excludeSpec : excludeRuleBackedSpec.excludeSpecs) {
    if (excludeSpec instanceof ExcludeRuleSpec || excludeSpec instanceof UnionSpec) {
        return super.doUnion(other);
    }
}

Reading the comment I guess UnionSpecs also don’t qualify as exact match rules.


(Niklas Grossmann) #14

I created example projects (one gradle, 4 ivy didn’t get it simpler) to reproduce the bug. You can download it here.


(Michael Barnathan) #15

Thanks for the test case! We’re actively working on a fix and should have something ready for you shortly.


(Michael Barnathan) #16

I’ve committed the fix and verified it against the project you posted - thanks again for that, it was very helpful in pinning this down. The fix is under review at the moment, but in the meantime, you can test it out by building a Gradle binary from source (master branch). Feel free to ping me if you encounter any issues with it!