sver
sver

Reputation: 942

How to write dependsOn in Custom plugin

I have a task in my build.gradle :

task makeJar(type: Copy) {
delete('dist/')
from('build/intermediates/bundles/release')
into('dist/')
include('classes.jar')
def jarName = new VersionName().getNameWithVersion() + '.jar'  
rename('classes.jar', jarName)
}
makeJar.dependsOn('clearTask', build)

Now, I want to remove this from my build.gradle and create a custom plugin like this : MakeJarTask.groovy (this is in eclipse project)

class MakeJarPluginTask extends Copy{
@TaskAction
def makeJar(){
    logger.lifecycle("creating a jar *********************")
    delete('dist/')
    from('build/intermediates/bundles/release')
    into('dist/')
    include('classes.jar')
            def jarName = new VersionName().getNameWithVersion() + '.jar'
    rename('classes.jar', jarName)
 }

Calling this Task in callGroovy.class (that implements Plugin)

project.tasks.create("makeJarPlugin1", MakeJarPluginTask.class){
 dependsOn("clearDist", "build")
}

But this doesn't give the correct output . The error is in last part, I think this is not the correct way to use dependsOn but I am not able to get how to use this. Any help will be highly appreciated.

Upvotes: 4

Views: 2458

Answers (1)

lance-java
lance-java

Reputation: 27984

Task task = project.tasks.create("makeJarPlugin1", MakeJarPluginTask.class);
task.dependsOn("clearDist", "build")

Upvotes: 5

Related Questions