Why is conventionMapping giving me a GroovyCastException?


(Jamie Olson) #1

I’m not trying to do anything complicated with conventionMapping, just assigning default values from an extension. Here’s what I’m actually doing:

‘’’

project.tasks.withType(com.eriwen.gradle.js.tasks.closure.BuildJsTask) {

conventionMapping.source = { project.javascript.source.main.js }

} ‘’’

If this isn’t enough to help, I can construct a complete example. The source is an ‘SourceDirectorySet’ object exposed within the task via getters and setters, but that doesn’t seem to be my problem:

‘’’ Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ‘com.eriwen.gradle.js.tasks.closure.BuildJsTask$_closure1@7429d88’ with class ‘com.eriwen.gradle.js.tasks.closure.BuildJsTask$_closure1’ to class ‘org.gradle.api.internal.IConventionAware’

at com.eriwen.gradle.js.tasks.closure.BuildJsTask.(BuildJsTask.groovy:54)

at com.eriwen.gradle.js.tasks.closure.BuildJsTask_Decorated.(Unknown Source)

at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:62)

at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)

at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:113) ‘’’


(Luke Daley) #2

You need:

conventionMapping.map("source") { project.javascript.source.main.js }

(Jamie Olson) #3

Ahh, right. I saw that in another thread and then forgot like an idiot.