Custom plug in to execute Java tasks


(m m) #1

Hi All, Thanks for the excellent guidance I had received for my earlier problems .

I am trying to use a custom plugin.

I have a project with a build.gradle below

apply plugin: ‘greeting’ apply plugin: ‘java’ dependencies {

compile project(’:my-lib’) } schemaObjectName {

className = “my.cool.app.Employee” } compileJava.doLast {

tasks.createBinding.execute() }

This is my plugin where I create dependencies and tasks to the project

class GreetingPlugin implements Plugin {

void apply(Project target) {

target.task(‘helloInsideGreeting’, type: GreetingTask)

println ’ creating new dependency ’

target.configurations.add(“bindGen”);

target.dependencies.add(“compile”,“org.slf4j:slf4j-api:1.6.5”);

target.dependencies.add(“bindGen”,“org.jibx:jibx-tools:1.2.3”);

target.dependencies.add(“bindGen”,“org.slf4j:log4j-over-slf4j:1.6.5”);

target.extensions.create(“schemaObjectName”, SchemaObjectName)

target.task(‘createBinding’, type:JavaExec) << {

classpath configurations.bindGen

classpath sourceSets.main.output.classesDir

main = “org.jibx.binding.generator.BindGen”

args “-w” , “-o” , “-t”, “${projectDir}/src/main/reosurces/bindgen”,

“${project.schemaObjectName.className}”

}

} }

class SchemaObjectName {

String className

I tested adding simple tasks dynamically to the project using the custom plug in and worked ( I also tried the greeting sample in the distribution ). I am trying to add a task of type JavaExec. When I run the task createBinding , I get the below exception

Caused by: java.lang.IllegalStateException: No main class specified

at org.gradle.process.internal.JavaExecHandleBuilder.build(JavaExecHandleBuilder.java:211)

Main class is already specified in the task. Is there any different to be specified in the custom plugin for type Java Exec ?


(m m) #2

please ignore the above question . The task was configured incorrectly .