Gradle 任务不执行它的依赖

Gradle task does not execute its dependency

我正在尝试使用 http://launch4j.sourceforge.net/ through this Gradle plugin https://github.com/TheBoegl/gradle-launch4j

当我执行 gradle clean launch4j 时,我得到以下输出。

:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:copyL4jLib
:generateXmlConfig
:createExeWithBin SKIPPED
:unzipL4jBin
:copyL4jBinLib
:createExeWithJar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':createExeWithJar'.
> meta-tagger.exe not created:
        launch4j: Icon doesn't exist.

我不明白为什么 copyResources 不是 运行。显然 :copyL4jLib 被执行了。不应该Gradle弄清楚copyResources在它之前先执行吗?

这是我的 gradle 版本信息。

Gradle 2.10
Build time:   2015-12-21 21:15:04 UTC
Build number: none
Revision:     276bdcded730f53aa8c11b479986aafa58e124a6

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_66 (Oracle Corporation 25.66-b18)
OS:           Windows 7 6.1 amd64

这是我的构建脚本。

plugins {
    id 'edu.sc.seis.launch4j' version '1.6.1'
    id 'java'
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

task copyResources(type: Copy) {
    from 'src/main/wrapper-resources/'
    into 'build/launch4j'
}

copyL4jLib {
    dependsOn copyResources
}

launch4j {
    mainClassName = 'com.mpinnegar.Main'
    icon = 'favicon.ico'
    headerType = 'console'
    errTitle = 'Image Tagger'
    stayAlive = true
}

tasks.copyL4jLib.dependsOn copyResources

插件似乎做了一些奇怪的事情。首先它创建任务(参见https://github.com/TheBoegl/gradle-launch4j/blob/develop/src/main/groovy/edu/sc/seis/launch4j/Launch4jPlugin.groovy#L50) and then replaces the task in an afterEvaluate block (see https://github.com/TheBoegl/gradle-launch4j/blob/develop/src/main/groovy/edu/sc/seis/launch4j/Launch4jPlugin.groovy#L122

要解决此问题,您应该能够将任务依赖性设置放在 afterEvaluate 块中,以确保您正在配置 replaced 任务:

afterEvaluate {
    copyL4jLib.dependsOn copyResources    
}