简体   繁体   中英

Cannot add task 'X' as a task with that name already exists

I have this gradle.build

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven-publish'
apply from: ext.gradleDir + '/common.gradle'
apply from: ext.gradleDir +'/base.gradle'
apply from: ext.gradleDir + '/integration_test.gradle'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'

project.archivesBaseName = 'client-services-lib'
uploadArchives.repositories.mavenDeployer.pom.groupId="com.waze.automation"


dependencies {
    compile('com.waze.automation:common:1.0.58')

    compile('com.sun.jersey:jersey-bundle:1.19')
    compile('com.sun.jersey:jersey-json:1.19')
    compile group:  'org.codehaus.jackson', name:'jackson-jaxrs', version: '1.1.1'

    compile('com.google.guava:guava:18.0')

    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile('org.hamcrest:hamcrest-all:1.3')
    testCompile('org.mockito:mockito-all:1.9.5')

}

war {
    from 'src/main' // include source files in war
}

and i run this

❯ ./gradlew build -i                                                                                                                                                                                                                      [12:40:40]
Starting Build
Settings evaluated using settings file '/Users/eladb/WorkspaceQa/java/MobileAutomationWebService/settings.gradle'.
Projects loaded. Root project using empty build file.
Included projects: [root project 'MobileAutomationWebService', project ':library-services', project ':web-services']
Evaluating root project 'MobileAutomationWebService' using empty build file.
Evaluating project ':library-services' using build file '/Users/eladb/WorkspaceQa/java/MobileAutomationWebService/library-services/build.gradle'.
Compiling build file '/Users/eladb/WorkspaceQa/java/MobileAutomationWebService/library-services/build.gradle' using StatementExtractingScriptTransformer.
Compiling build file '/Users/eladb/WorkspaceQa/java/MobileAutomationWebService/library-services/build.gradle' using BuildScriptTransformer.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/eladb/WorkspaceQa/gradle/base.gradle' line: 28

* What went wrong:
A problem occurred evaluating script.
> Cannot add task ':library-services:wrapper' as a task with that name already exists.

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

and this base.gradle

project.ext.flag = { String name ->
    if (!project.hasProperty(name)) {
            return false
    }

    String value = project.ext[name]
    value = value.toLowerCase()

    if (value == "true" || value == "yes" || value == "1") {
            return true
    }

    if (value == "false" || value == "no" || value == "0" || value == "") {
            return false
    }

    throw new IllegalArgumentException("Invalid value of flag property \"$name\": \"$value\", must be one of true, false, yes, no, 0, 1 or empty")
}

////////////////////////////////////////////////////////////////////////////////////////
// Standard settings (can be overridden on a per-project basis)
////////////////////////////////////////////////////////////////////////////////////////

sourceCompatibility = 1.6

compileJava.options.encoding = 'UTF-8'

task wrapper(type: Wrapper) {
    gradleVersion = '1.12'
}

////////////////////////////////////////////////////////////////////////////////////////
// Waze "Be Fast" (tm)
////////////////////////////////////////////////////////////////////////////////////////
configurations.all {
    if (flag('waze.beFast')) {
        resolutionStrategy.cacheDynamicVersionsFor 1, 'hours'
    }
    else {
        resolutionStrategy.cacheDynamicVersionsFor 0, 'minutes'
    }
}

////////////////////////////////////////////////////////////////////////////////////////
// Common repositories config.
////////////////////////////////////////////////////////////////////////////////////////
repositories {
    mavenCentral()
    maven {
        url getWazeRepoUrl()
    }
    maven {
        url "http://www.hibernatespatial.org/repository"
    }
}

def getWazeRepoUrl() {
    if (project.hasProperty('buildMachine')) {
        "/data/archiva/repositories/internal/"
    } else {
        "https://waze-repo.corp.google.com/archiva/repository/internal/"
    }
}

////////////////////////////////////////////////////////////////////////////////////////
// Add 'provided' scope which is missing from Gradle by default.
////////////////////////////////////////////////////////////////////////////////////////
configurations {
    provided
}

sourceSets {
    main {
        compileClasspath += configurations.provided
        runtimeClasspath += configurations.provided
    }
    test {
        compileClasspath += configurations.provided
        runtimeClasspath += configurations.provided
    }
}

////////////////////////////////////////////////////////////////////////////////////////
// Eclipse-specific configuration.
////////////////////////////////////////////////////////////////////////////////////////
    if (hasProperty('web') && web) {
        apply plugin: 'eclipse-wtp'
    } else {
        apply plugin: 'eclipse'
    }

    tasks.eclipse.dependsOn(cleanEclipse)

    eclipse {
        pathVariables 'GRADLE_USER_HOME': gradle.gradleUserHomeDir

        classpath {
            plusConfigurations += [configurations.provided]
            noExportConfigurations += [configurations.provided]
        }
    }
    project.afterEvaluate {
      // use jre lib matching version used by project, not the workspace default
        if (project.sourceCompatibility != null) {
            def target = project.targetCompatibility.toString()
            def containerPrefix = "org.eclipse.jdt.launching.JRE_CONTAINER"
            def containerSuffix = '/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-' + target
            if (containerSuffix != null) {
                project.eclipse.classpath {
                    containers.removeAll { it.startsWith(containerPrefix) }
                    containers.add(containerPrefix + containerSuffix)
                }
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////////////
// IntelliJ-specific configuration.
////////////////////////////////////////////////////////////////////////////////////////
if (flag('waze.idea')) {
    apply plugin: 'idea'

    idea {
        module {
            scopes.PROVIDED.plus += [configurations.provided]
        }
    }
}

I cannot understand why it says Cannot add task ':library-services:wrapper' as a task with that name already exists.

I cannot see my gradle.build even try to add "wrapping" task

my gradle.build doesn't try to add a task "wrapper" and it doesn't appear on base.gradle' line: 28

Do you apply base.gradle to all your sub-projects? Do you apply it to your root project as well?

The wrapper task in gradle is only added to the root project and not to the subprojects. If you're applying base.gradle to all your projects, that would be the cause of your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM