[GRADLE-2689] Gradle fails extending configuration from parent project Created: 22/Feb/13  Updated: 22/Nov/16  Resolved: 22/Nov/16

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-6, 1.0-milestone-9, 1.0, 1.4
Fix Version/s: None

Type: Bug
Reporter: Jesper Skov Assignee: Unassigned
Resolution: Won't Fix Votes: 0

Attachments: Zip Archive gradle-npe.zip    

 Description   

We declare some configurations in the root project, which are used to extend configurations in child projects.

Unfortunately it causes a NPE:

CP main : C:\udvikler\ws\e43-dev\gradle-npe\lib\main-dep.jar

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\udvikler\ws\e43-dev\gradle-npe.child\build.gradle' line: 18

* What went wrong:
A problem occurred evaluating project ':gradle-npe.child'.
> Could not resolve all dependencies for configuration ':gradle-npe.child:compile'.
   > java.lang.NullPointerException (no error message)

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':gradle-npe.child'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)
        at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
        at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:466)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:77)
        at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
        at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
        at org.gradle.api.internal.Actions$CompositeAction.execute(Actions.java:78)
        at org.gradle.api.internal.Actions$TransformingActionAdapter.execute(Actions.java:130)
        at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:442)
        at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:437)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:40)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
        at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
        at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
        at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
        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:48)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.Main.main(Main.java:39)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':gradle-npe.child:compile'.
        at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.wrapException(ErrorHandlingArtifactDependencyResolver.java:49)
        at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.access$000(ErrorHandlingArtifactDependencyResolver.java:27)
        at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$BrokenResolvedConfiguration.rethrowFailure(ErrorHandlingArtifact
DependencyResolver.java:129)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:461)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getFiles(DefaultConfiguration.java:202)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source)
        at org.gradle.api.internal.file.AbstractFileCollection.getAsPath(AbstractFileCollection.java:64)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getAsPath(Unknown Source)
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.getProperty(BeanDynamicObject.java:146)
        at org.gradle.api.internal.BeanDynamicObject.getProperty(BeanDynamicObject.java:102)
        at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:78)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getProperty(Unknown Source)
        at build_64btroc9usq3m8jj5juo8kdagu.run(C:\udvikler\ws\e43-dev\gradle-npe.child\build.gradle:18)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
        ... 32 more
Caused by: java.lang.NullPointerException
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.findAncestors(DependencyGraphBuilder.java:695)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.<init>(DependencyGraphBuilder.java:689)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.<init>(DependencyGraphBuilder.java:672)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ResolveState.getConfigurationNode(DependencyGraphBuilder.java:471)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.findAncestors(DependencyGraphBuilder.java:696)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.<init>(DependencyGraphBuilder.java:689)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.<init>(DependencyGraphBuilder.java:672)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ResolveState.getConfigurationNode(DependencyGraphBuilder.java:471)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ResolveState.<init>(DependencyGraphBuilder.java:443)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:63)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:69)
        at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:36)
        at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:34)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:130)
        at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:53)
        at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:34)
        at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:39)
        at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyRes
olver.java:44)
        at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:37)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveNow(DefaultConfiguration.java:240)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getResolvedConfiguration(DefaultConfiguration.java:230)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getResolvedConfiguration(Unknown Source)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:459)
        ... 42 more


BUILD FAILED

Total time: 1.997 secs

On 1.0-milestone-3 the result is:

CP main : C:\udvikler\ws\e43-dev\gradle-npe\lib\main-dep.jar
CP child : C:\udvikler\ws\e43-dev\gradle-npe.child\lib\child-dep.jar;C:\udvikler\ws\e43-dev\gradle-npe\lib\main-dep.jar
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:gradle-npe.child:compileJava UP-TO-DATE
:gradle-npe.child:processResources UP-TO-DATE
:gradle-npe.child:classes UP-TO-DATE

BUILD SUCCESSFUL

Total time: 1.363 secs

The two (simple!) example projects are included in gradle-npe.zip.
I simply run gradle in the 'gradle-npe' project.

This works on 1.0-milestone-3. The versions I've tested are listed in Affected Versions.



 Comments   
Comment by Jesper Skov [ 11/Mar/13 ]

Same behavior on 1.5-rc-1

Comment by Jesper Skov [ 24/Jun/13 ]

I just tried poking around in the code to see if I could fix it.

Not sure I succeeded, because I have not understood enough of the code to be sure.

But the below patch makes the little test attached above work.

index a786ecf..1cc295d 100644
--- a/subprojects/core-impl/src/main/groovy/org/gradle/api/internal/artifacts/ivyservice/resolveengine/DependencyGraphBuilder.java
+++ b/subprojects/core-impl/src/main/groovy/org/gradle/api/internal/artifacts/ivyservice/resolveengine/DependencyGraphBuilder.java
@@ -697,10 +697,15 @@ public class DependencyGraphBuilder {
             moduleRevision.addConfiguration(this);
         }

-        void findAncestors(String config, ResolveState container, Set<String> ancestors) {
-            ancestors.add(config);
-            for (String parentConfig : descriptor.getConfiguration(config).getExtends()) {
-                ancestors.addAll(container.getConfigurationNode(moduleRevision, parentConfig).heirarchy);
+        void findAncestors(String configName, ResolveState container, Set<String> ancestors) {
+            Configuration configuration = descriptor.getConfiguration(configName);
+            if (configuration == null) {
+               ancestors.add(":" + configName);
+            } else {
+                ancestors.add(configName);
+                   for (String parentConfig : configuration.getExtends()) {
+                       ancestors.addAll(container.getConfigurationNode(moduleRevision, parentConfig).heirarchy);
+                   }
             }
         }

I don't understand how the hierarchy entries translate to artifacts; the method in the same class asks Ivy.
So odds are that this only makes this particular test work...

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Jesper Skov [ 16/Nov/16 ]

Please close it.

Comment by Benjamin Muschko [ 22/Nov/16 ]

Closing as indicated by comment.

Generated at Wed Jun 30 12:28:48 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.