Philip Crotwell wrote:
On Fri, Sep 18, 2009 at 3:36 AM, Hans Dockter <[email protected]> wrote:
Hi Philip,

On Sep 16, 2009, at 10:44 PM, Philip Crotwell wrote:

Hi

I wrote a quick task to test getting the version, group and name from
a dependency, but am getting a failure using this within the
samples/userguide/multiproject/dependencies/java example.
Interestingly it prints out the only dependency artifact (shared 1.0
org.gradle.sample) for the project dependency, but is then failing as
if there is a second item that is null in the default configuration.

Bug? Or am I doing something wrong?

  task play << { task ->
      task.project.configurations.default.files { artifact -> print
"$artifact.name ${artifact.version} ${artifact.group}" }
  }
To resolve rroject dependencies they need to be build first. You can enforce
this by:

task play(dependsOn: configurations.default.buildDependencies) { artifact ->
... }

- Hans


Humm, well I still get the same error. I think that is it the second
dependency that is giving the problem, not the project one. Here is
the new task and the error. Seems very strange that gradle jar works
fine, but play fails since a nonresolving dependency ought to be as
much of a problem for jar as for play. I guess I still don't
understand what is going on behind the scenes as all the task is
asking for is the basic information that is directly in the
build.gradle file, so resolving shouldn't really be needed.


By calling the files() method, you are asking for the configuration to be resolved and all the files to be located and downloaded, as the files() method returns the resolved files. So it's going to fail if any of the files don't exist. I suspect this isn't the cause of your problem - see below.

You might want to try Configuration.allDependencies instead. It doesn't do any resolving. Have a look at the API for Configuration for some other options: http://gradle.org/0.7/docs/javadoc/org/gradle/api/artifacts/Configuration.html

Anyway, here is the error if you can think of any other reason why
this might be failing.

thanks,
PHilip


  task play(dependsOn: configurations.default.buildDependencies) << { task ->
       task.project.configurations.default.files { artifact ->
            print "${artifact.getClass()} ${artifact.name}
${artifact.version} ${artifact.group}\n"
       }
   }


The closure that you pass to the files() method is a selector, in that it must return a non-null value that Groovy can convert to boolean. The last statement of your closure is a method with a void return type, so the return value will be null. Hence the NPE. Groovy really should convert null to false in this instance, but it isn't for some reason.

Try:

task play(dependsOn: configurations.default.buildDependencies) << { task ->
      task.project.configurations.default.files { artifact ->
           print "${artifact.getClass()} ${artifact.name}
${artifact.version} ${artifact.group}\n"
           *true*
      }
  }


I've added a JIRA issue to remind us to do something better in the case where you forget to return a value.

rabbit:~/dev/gradle.orig/build/distributions/exploded/samples/java/multiproject/api
crotwell$ gradle -S jar play
:shared:compileJava
:shared:processResources
:shared:compile
:shared:jar
:shared:uploadDefaultInternal
:api:compileJava
:api:processResources
:api:compile
:api:jar
:api:play
class org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency
shared 1.0 org.gradle

FAILURE: Build failed with an exception.

* Where:
Build file 
'/private/var/automount/home/crotwell/dev/gradle.orig/build/distributions/exploded/samples/java/multiproject/api/build.gradle'

* What went wrong:
Execution failed for task ':api:play'.
Cause: Could not resolve all dependencies for configuration 'default'.
Cause: java.lang.NullPointerException (no error message)

* Exception is:
org.gradle.api.GradleScriptException: Build file
'/private/var/automount/home/crotwell/dev/gradle.orig/build/distributions/exploded/samples/java/multiproject/api/build.gradle'
Execution failed for task ':api:play'.
        at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:233)
        at 
org.gradle.execution.DefaultTaskExecuter.executeTask(DefaultTaskExecuter.java:165)
        at 
org.gradle.execution.DefaultTaskExecuter.doExecute(DefaultTaskExecuter.java:156)
        at 
org.gradle.execution.DefaultTaskExecuter.execute(DefaultTaskExecuter.java:74)
        at 
org.gradle.execution.TaskNameResolvingBuildExecuter.execute(TaskNameResolvingBuildExecuter.java:174)
        at 
org.gradle.execution.DelegatingBuildExecuter.execute(DelegatingBuildExecuter.java:54)
        at org.gradle.GradleLauncher.doBuildStages(GradleLauncher.java:164)
        at org.gradle.GradleLauncher.doBuild(GradleLauncher.java:123)
        at org.gradle.GradleLauncher.run(GradleLauncher.java:94)
        at org.gradle.Main.execute(Main.java:100)
        at org.gradle.Main.main(Main.java:43)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.gradle.BootstrapMain.main(BootstrapMain.java:53)
Caused by: org.gradle.api.artifacts.ResolveException: Could not
resolve all dependencies for configuration 'default'.
        at 
org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingIvyService.wrapException(ErrorHandlingIvyService.java:63)
        at 
org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingIvyService.access$000(ErrorHandlingIvyService.java:28)
        at 
org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingIvyService$ErrorHandlingResolvedConfiguration.getFiles(ErrorHandlingIvyService.java:92)
        at 
org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:494)
        at 
org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.files(DefaultConfiguration.java:162)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
        at 
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at 
build_gradle_54421c5eb6db1d0ae95e3229048fd89d$_run_closure1_closure4.doCall(/private/var/automount/home/crotwell/dev/gradle.orig/build/distributions/exploded/samples/java/multiproject/build.gradle:18)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
        at 
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:880)
        at 
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.gradle.api.ClosureTaskAction.execute(DefaultTask.groovy:82)
        at org.gradle.api.ClosureTaskAction.execute(DefaultTask.groovy)
        at org.gradle.api.internal.AbstractTask.doExecute(AbstractTask.java:258)
        at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:223)
        ... 15 common frames omitted
Caused by: java.lang.NullPointerException
        at $Proxy20.isSatisfiedBy(Unknown Source)
        at org.gradle.api.specs.Specs.filterIterable(Specs.java:51)
        at 
org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver$1.getFiles(SelfResolvingDependencyResolver.java:48)
        at 
org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingIvyService$ErrorHandlingResolvedConfiguration.getFiles(ErrorHandlingIvyService.java:90)
        ... 43 common frames omitted

BUILD FAILED

Total time: 12.857 secs


------------------------------------------------------------
Gradle 0.8-20090918111807-0400
------------------------------------------------------------

Gradle buildtime: Friday, September 18, 2009 11:18:07 AM EDT
Groovy: 1.6.4
Ant: Apache Ant version 1.7.0 compiled on December 13 2006
Ivy: 2.1.0-rc2
Java: 1.5.0_19
JVM: 1.5.0_19-138
JVM Vendor: "Apple Computer, Inc."
OS Name: Mac OS X

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to