Gradle clean <customTask> 不工作

标签 gradle

我有一个自定义任务来执行 Websphere EJBDeploy。我已经定义了输入和输出,并获得了成功的增量编译,但我无法让自动生成的清理任务正常工作。

根据文档,对于名为“ejbDeploy”的具有定义输出的自定义任务,cleanEjbDeploy task should be automatically generated .

Pattern: clean<TaskName>: Cleans the output files of a task.

所以这是我的自定义任务:

task ejbDeploy(dependsOn: 'jar'){
    srcFile = file(jar.archivePath)
    destDir = new File("build/ejbDeploy")

    inputs.file srcFile
    outputs.dir destDir

    def cp = project.files(
        project.sourceSets.main.output.classesDir,
        project.sourceSets.main.resources,
        project.configurations.runtime
        ).getAsPath()

    doLast{
        destDir.mkdirs()

        exec{
            executable = wasEjbDeploy
            workingDir = destDir
            args = [
                jar.archivePath,
                ".",
                jar.archiveName,
                "-cp",
                cp
            ]
        }   
    }
}

有人知道为什么干净规则不起作用吗?

[编辑]

这是完整的(匿名的)文件内容(自最初的问题发布以来已经改变):

version = '1.0-SNAPSHOT'
group = 'com.company'

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath group: 'name.benjaminAbbitt', name: 'WASEjbDeploy', version: '1.0-SNAPSHOT'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'base'

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    compile 'javax.mail:mail:1.4.5'
    compile 'log4j:log4j:1.2.16'
    compile files(fileTree(dir: 'lib', includes: ['*.jar']) )
}

task ejbDeploy(type:name.benjaminAbbitt.WASEjbDeploy, dependsOn: 'jar'){
    wasEjbDeployPath = wasEjbDeploy
}

这是“$gradle tasks”的相关部分

build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend
on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles the main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles the test classes.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
dependencies - Displays the dependencies of project ':project'.
help - Displays a help message
projects - Displays the sub-projects of project ':project'.
properties - Displays the properties of project ':project'.
tasks - Displays the tasks runnable from project ':project' (some of the
displayed tasks may belong to subprojects).

IDE tasks
---------
cleanEclipse - Cleans all Eclipse files.
eclipse - Generates all Eclipse files.

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

Other tasks
-----------
ejbDeploy

Rules
-----
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belongin
g to a configuration.
Pattern: clean<TaskName>: Cleans the output files of a task.

To see all tasks and more detail, run with --all.

BUILD SUCCESSFUL

Total time: 3.321 secs

最佳答案

clean 规则由base 插件提供。由于许多其他插件(例如 java)已经应用了 base 插件,您通常不必自己应用 base 插件。但以防万一:

apply plugin: "base"

关于Gradle clean <customTask> 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12320081/

相关文章:

android - 无法合并 dex gradle 3.0.1

java - 为什么IntelliJ IDEA无法确定Java版本?

安卓工作室 : Error:Unable to find optional library: org. apache.http.legacy

gradle - 我可以在所有模块的根项目中定义 buildscript 存储库吗

android studio error-混合版本会导致运行时崩溃

gradle - Gradle无法找到现有的M2库

gradle - 使用 Gradle 将资源和配置文件添加到 JAR

java - 无法解析Android Studio中的Symbol v7和appComapat Activity导入

android - Gradle项目同步失败:对等方未通过身份验证

gradle - Android Studio Gradle 构建 : NDK error