Java build.gradle-找不到参数的方法copyDeps()

Java build.gradle-找不到参数的方法copyDeps(),java,gradle,groovy,build.gradle,dsl,Java,Gradle,Groovy,Build.gradle,Dsl,下面是build.gradle文件: plugins({ id('application') id 'java' id('com.github.johnrengelman.shadow').version('4.0.1') }) allprojects( { apply(plugin: 'application') apply(plugin: 'java') apply(plugin: 'com.github.johnrengelman.shadow'

下面是
build.gradle
文件:

plugins({
  id('application')
  id 'java'
  id('com.github.johnrengelman.shadow').version('4.0.1')
})

allprojects( 
  {
    apply(plugin: 'application')
    apply(plugin: 'java')
    apply(plugin: 'com.github.johnrengelman.shadow')

    repositories({
      mavenCentral()
    })

    ext({
      vertxVersion = '3.7.0'
      commitTimestamp = {
        return "git log -1 --pretty=format:%cd --date=format:%Y%m%d%H%M%S".execute().text.trim()
      }
      commitId = {
        return "git rev-parse --short HEAD".execute().text.trim()
      }
      buildId = {
        if (System.getenv("BUILD_ID") != null) return ".${System.getenv("BUILD_ID")}"
        else return ""
      }
    })

    group = 'com.pluralsight.docker-production-aws'
    version = System.getenv("APP_VERSION") ?: "${commitTimestamp()}.${commitId()}${buildId()}"
    sourceCompatibility = '1.8'
    mainClassName = 'io.vertx.core.Launcher'

    dependencies({
      compile("io.vertx:vertx-core:$vertxVersion")
      compile("io.vertx:vertx-hazelcast:$vertxVersion")
      compile("io.vertx:vertx-service-discovery:$vertxVersion")
      compile("io.vertx:vertx-dropwizard-metrics:$vertxVersion")
      compile("com.typesafe:config:1.3.0")
      compile("com.hazelcast:hazelcast-cloud:3.6.5")
      testCompile("io.vertx:vertx-unit:$vertxVersion")
      testCompile("junit:junit:4.12")
      testCompile("org.assertj:assertj-core:3.5.2")
      testCompile("com.jayway.awaitility:awaitility:1.7.0")
    })

    task(copyDeps(type: Copy), {
        from (configurations.runtime + configurations.testRuntime).exclude('*')
        into('/tmp')
      }
    )

    test(
      {
        testLogging(
          {
          events("passed", "skipped", "failed")
          }
        )
        reports(
          {
            junitXml.enabled = true
            junitXml.destination = file("${rootProject.projectDir}/build/test-results/junit")
            html.enabled = false
          }
        )
      }
    )

  }
)

task(testReport(type: TestReport), {
    destinationDir = file("${rootProject.projectDir}/build/test-results/html")
    reportOn(subprojects*.test)
  }
)

test(
  {
    dependsOn(testReport)
  }
)

configure(
  (subprojects - project(':microtrader-common')), 
  {
    shadowJar(
      {
        destinationDir = file("${rootProject.projectDir}/build/jars")
        classifier = 'fat'
        mergeServiceFiles(
          {
            include('META-INF/services/io.vertx.core.spi.VerticleFactory')
          }
        )
      }
    )
  }
)

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

/gradlew clean test shadowJar上出现以下错误:

    > Could not find method copyDeps() for arguments 
对于问题代码段:

task(copyDeps(type: Copy), {
    from (configurations.runtime + configurations.testRuntime).exclude('*')
    into('/tmp')
  }

task(testReport(type: TestReport), {
    destinationDir = file("${rootProject.projectDir}/build/test-results/html")
    reportOn(subprojects*.test)
  }
)

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

/gradlew
命令可使用以下代码段语法,而无需使用语法:

    task copyDeps(type: Copy) {
      from (configurations.runtime + configurations.testRuntime) exclude '*'
      into '/tmp'
    }


task testReport(type: TestReport) {
  destinationDir = file("${rootProject.projectDir}/build/test-results/html")
  reportOn subprojects*.test
}


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

build.gradle
是否存在语法问题?使用paranthesis…我们更喜欢使用paranthesis

显示了如何定义自定义任务的示例

下面是如何以冗长的方式定义任务

tasks.create('copyDeps', Copy, {
    from(file('srcDir'))
    into(buildDir)
})
任务是使用创建的,它为
create
方法提供了多个重载。以下是一个子集:

  • 创建​(字符串名称)
  • 创建​(字符串名称,闭包配置闭包)
  • 创建​(字符串名称、类类型、操作选项、闭包配置闭包)

好吧,如果我从上一个问题和这一个问题中理解的话,你不想使用Gradle提供的任何DSL并使用普通/脚本化语法,对吗?@FranciscoMateo我总是喜欢使用脚本化语法在Jenkins中编写groovy管道脚本。这里有一个例子:@FranciscoMateo我想使用syntax
id(“com.github.johnrengelman.shadow”).version(“5.2.0”)
而不是
id“com.github.johnrengelman.shadow”version“5.2.0”
,因为前面的语法更具可读性,因为前面的语法清楚地告诉我这是链式表达式,由于使用了偏执和点运算符。我回答你的问题了吗?哦,好吧,我想我现在明白了,你提到詹金斯。我从经验中知道,如果您不知道语法/步骤,那么一个
Jenkinsfile
就不太友好。对于你的问题1和2,这是正确的,应该从看它开始。一般来说,只要省略了
()
,您就可以放回去。在省略了
的地方,您也可以放回去。testReport和包装器任务也是这样吗?你能完成答案吗?