Hi,my gradle-groovysh-plugin does not work with Gradle 2.0. I am trying to fix that, but I am stuck. My goal would be to create a jar that works with both gradle 1.x and gradle 2.x, becuase else it would be twice the hassle to release and provide support.
What seems to be causing the main problem is that I subclass org.gradle.api.tasks.compile.JavaCompile, which lead to this
Caused by: java.lang.VerifyError: (class: com/tkruse/gradle/groovysh/PatchedMainCompileTask, method: super$7$setJavaCompiler signature: (Lorg/gradle/api/internal/tasks/compile/Compiler;)V) Illegal use of nonvirtual function call
at com.tkruse.gradle.groovysh.ShellTask.class$(ShellTask.groovy)
at com.tkruse.gradle.groovysh.ShellTask.$get$$class$com$tkruse$gradle$groovysh$PatchedMainCompileTask(ShellTask.groovy)
at com.tkruse.gradle.groovysh.ShellTask.<init>(ShellTask.groovy:13)
at com.tkruse.gradle.groovysh.BuildShellTask.<init>(BuildShellTask.groovy:24)
at com.tkruse.gradle.groovysh.BuildShellTask_Decorated.<init>(Unknown Source)
at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:48)
at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:124)
I can rebuild a jar using gradle2, but then that jar will not run with gradle 1.x:
Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling
at com.tkruse.gradle.groovysh.PatchedMainCompileTask.<clinit>(PatchedMainCompileTask.groovy:12)
I subclassed JavaCompile because i needed the plugin to generate a java class and compile it, like this.
class PatchedMainCompileTask extends JavaCompile {
static final String NAME = 'compileGroovyshPatchedMain'
static final String PATCH_CLASS_NAME = 'PatchedMain'
static final String PATCH_CLASS_CAN_NAME = 'org.codehaus.groovy.tools.shell.' + PATCH_CLASS_NAME
static final String CONFIGURATION_NAME = 'appShellCompileMainConf'
PatchedMainCompileTask() {
this.group = 'help'
this.outputs.upToDateWhen { false }
}
@Override
void executeWithoutThrowingTaskFailure() {
project.configurations.create(CONFIGURATION_NAME)
TaskHelper.addGroovyDependencies(project, CONFIGURATION_NAME, project.groovysh.groovyVersion)
File genFile = TaskHelper.generatePatchedMain(project, PATCH_CLASS_NAME)
this.destinationDir = new File(project.buildDir, 'groovyshClasses')
this.source = genFile
this.classpath = (project.configurations.getByName(CONFIGURATION_NAME).asFileTree
+ project.files(genFile.getParent()))
super.executeWithoutThrowingTaskFailure()
}
}
So, is it possible at all to create custom plugins that are compatible with gradle1.x and gradle 2.x? Is there any easy way for me to get that? Else is there any complex way? Or what is the recommendation for releasing the same plugin in separate versions for gradle 1 and gradle 2?