build.gradle-找不到方法copyDeps()作为参数 [英] build.gradle - Could not find method copyDeps() for arguments

查看:210
本文介绍了build.gradle-找不到方法copyDeps()作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是 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 

找不到问题代码段的方法copyDeps():

for problem code snippet:

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 命令与以下代码片段语法一起使用,而没有括号:


./gradlew Command works with below code snippet syntax without paranthesis:

    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 有语法问题?使用偏瘫...我们更喜欢使用偏瘫


Does build.gradle have syntax issue? using paranthesis...We prefer using paranthesis

推荐答案

https://docs.gradle.org/current/userguide/more_about_tasks.html 显示了如何定义自定义任务的示例。

https://docs.gradle.org/current/userguide/more_about_tasks.html shows examples of how to define custom tasks.

这是您以冗长的方式定义任务的方法。

Here is how you can define your tasks the verbose way.

tasks.create('copyDeps', Copy, {
    from(file('srcDir'))
    into(buildDir)
})

使用 TaskContainer ,它为 create 方法提供了几个重载。这是一个子集:

The tasks are created using the TaskContainer which offers several overloads for the create method. Here is a subset:


  • create((字符串名)

  • create(字符串名称,Closure configureClosure)

  • create(字符串名称,Class< T>类型,Action< ;? super T>配置)<-这是上面使用的

  • 创建(Map< String,??>选项,闭包configureClosure)

  • create​(String name)
  • create​(String name, Closure configureClosure)
  • create​(String name, Class<T> type, Action<? super T> configuration) <-- this is the one used above
  • create​(Map<String,​?> options, Closure configureClosure)

这篇关于build.gradle-找不到方法copyDeps()作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆