Grails gradle "a task with the same name already exists"

I am trying to create a test task rule using the example in grails gradle doc , but I keep getting "a task with the same name already exists".

My build script looks like this:

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] // } //} } 

Running $gradle grails-test-integration or actually nothing from the form $gradle grails-test-app-xxxxxxxx gives the error "Unable to add task" gradle grails-test-app-xxxxxxxx as a task with the same name already exists. "

Can someone please tell me how I can resolve this error? Thanks.

+7
build.gradle gradle grails-plugin
source share
1 answer

If you do not mind redefining the task created by the plugin, you can try

 task(taskName, type: GrailsTestTask, overwrite: true) 

In general, when using task rules that can be called several times (for example, if you have several tasks depending on the task that your rules ultimately added), I use the following test before creating the task:

if (tasks.findByPath(taskName) == null) {tasks.create(taskName)}

This will call the task () constructor only if this task name does not exist.

+10
source share

All Articles