有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法添加任务“X”,因为具有该名称的任务已存在

我有这个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
}

我负责这个

❯ ./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

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

我不明白它为什么说Cannot add task ':library-services:wrapper' as a task with that name already exists.

我看不见我的梯度。构建甚至尝试添加"wrapping"任务

我的格拉德尔。构建不会尝试添加任务“包装器” 而且它不会出现在基地上。格雷德尔热线:28


共 (1) 个答案

  1. # 1 楼答案

    你申请基地吗。gradle对你所有的子项目都感兴趣?您是否也将其应用于根项目

    gradle中的包装器任务只添加到根项目,而不是子项目。如果你申请base。向你所有的项目致敬,这将是你问题的原因