How to use "Copy" task inside a standalone plugin or a groovy/java class


(Yong Cheng) #1

How to use “Copy” task inside a standalone plugin or a groovy/java class http://www.gradle.org/docs/current/javadoc/org/gradle/api/tasks/Copy.html

having a hard time to figure out to use this following syntax inside a class instead of “build.gradle”

task copyTask(type: Copy) {
    from 'src/main/webapp'
    into 'build/explodedWar'
    include "*.*"
}

(Benjamin Muschko) #2

You can add new tasks to the Project instance. Here’s an example on how to make this happen in a class that implements Plugin.

apply plugin: MyPlugin
  class MyPlugin implements Plugin<Project> {
    @Override
    void apply(Project project) {
        project.task('copyTask', type: Copy) {
            from 'src/main/webapp'
            into 'build/explodedWar'
            include "*.*"
        }
    }
}