Gradle:如何从其他任务调用应用程序插件提供的隐式任务

时间:2016-07-19 12:06:35

标签: java gradle build build.gradle gradle-plugin

我需要执行“应用程序”提供的运行任务。完成' copySrcToTempDir'任务。

我试过

1)run.dependsOn copySrcToTempDir - > BuildFail

2)run.mustRunAfter copySrcToTempDir - >但不会执行运行任务。

 apply plugin:'application'

        repositories {
           flatDir {
               dirs 'lib'
           }
        }
        dependencies {
           compile name: 'zip4j_1.3.2'
        }
        mainClassName = "com.md.zippwd.ZipWithPassword"

        task copySrcToTempDir(type: Copy){
        from "D:\\DemoProject"
        into "D:\\Temp"
      }
    }
    // run.dependsOn copySrcToTempDir      
    // run.mustRunAfter copySrcToTempDir   

provided gradle command accordingly

gradle copySrcToTempDir  

gradle run

please suggest me i'm not finding any solution.

2 个答案:

答案 0 :(得分:1)

apply plugin:'application'

sourceSets.main.java.srcDirs = ['src']

    repositories {
       flatDir {
           dirs 'lib'
       }
    }
    dependencies {
       compile name: 'zip4j_1.3.2'
    }
    mainClassName = "com.md.zippwd.ZipWithPassword"

    task copySrcToTempDir(type: Copy){
    from "D:\\DemoProject"
    into "D:\\Temp"
  }
}

task finaltask(dependsOn: ['copyArsWebApp', 'run'])

描述

We need to add sourceSet if folder is not like  src->java->main

and to use run task, make it is independent because it already depending upon application plugin's task like compile , classes ....

非常感谢Ajay Deshwal。

答案 1 :(得分:0)

run.dependsOn copySrcToTempDir正在为我工​​作。我正在使用gradle 2.5。你正在执行哪个gradle任务?运行

尝试使用:

tasks.run.dependsOn("copySrcToTempDir")