【发布时间】:2014-05-01 06:33:29
【问题描述】:
我正在尝试使用in the grails gradle doc 提供的示例创建测试任务规则,但我不断收到“具有该名称的任务已存在”错误。
我的构建脚本如下:
import org.grails.gradle.plugin.tasks.* //Added import here else fails with "Could not find property GrailsTestTask"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0"
}
}
version "0.1"
group "example"
apply plugin: "grails"
repositories {
grails.central() //creates a maven repo for the Grails Central repository (Core libraries and plugins)
}
grails {
grailsVersion = '2.3.5'
groovyVersion = '2.1.9'
springLoadedVersion '1.1.3'
}
dependencies {
bootstrap "org.grails.plugins:tomcat:7.0.50" // No container is deployed by default, so add this
compile 'org.grails.plugins:resources:1.2' // Just an example of adding a Grails plugin
}
project.tasks.addRule('Pattern: grails-test-app-<phase>') { String taskName ->
println tasks //shows grails-test-app-xxxxx task. Why?
//if (taskName.startsWith('grails-test-app') && taskName != 'grails-test-app') {
// task(taskName, type: GrailsTestTask) {
// String testPhase = (taskName - 'grails-test-app').toLowerCase()
// phases = [testPhase]
// }
//}
}
正在运行$gradle grails-test-integration
或者实际上$gradle grails-test-app-xxxxxxxx 形式的任何内容都会产生错误“无法将任务'gradle grails-test-app-xxxxxxxx 添加为具有该名称的任务已经存在”。
谁能告诉我如何解决这个错误?谢谢。
【问题讨论】:
-
您是否尝试过使用不同的任务名称模式?您是否尝试在添加任务之前检查它是否存在?
-
嗨,彼得,是的,我尝试了不同的模式,但它总是失败并出现错误“无法添加任务...同名的任务已经存在。”
-
奇怪。问题可能与
grails-gradle-plugin(我不熟悉)有关。 -
我最好的猜测是
grails-gradle-plugin本身添加了一个委托给 Grails 构建系统的“catch all”任务规则。在这种情况下,您可能无法在使用此插件时声明自己的任务规则。 -
@PeterNiederwieser:我认为你是对的。查看插件的源代码,有一个 addRule 可以为前缀为“grails-”的模式创建任务。有没有办法可以创建与插件之前相同模式的任务? IE。在 build.gradle 中,如何在插件之前创建 grails-XXX 形式的任务?还是不明智?
标签: gradle grails-plugin build.gradle