【问题标题】:gradle build is failing when i have multiple tasks with run time parameters当我有多个带有运行时参数的任务时,gradle build 失败
【发布时间】:2020-05-08 17:31:25
【问题描述】:

在我的 gradle 构建中有多个任务,我正在传递参数运行时间。当我进行 gradle 构建时构建失败

下面是两个带参数运行时间的任务

任务1

task downloadFile(type: MyDownload) {
    sourceUrl = srcUrl
    target = new File(destUrl, 'build.zip')
}

任务2

task unzip(type: Copy) {
    def zipFile = file(zipFileInput)
    def outputDir = file(zipFileOutput)

    from zipTree(zipFile)
    into outputDir
}

请提出解决问题的解决方案

【问题讨论】:

  • 什么错误?什么输入?
  • 我正在运行这样的任务 gradle unzip -PzipFileInput="location of the file" -PzipFileOutput="location of the file"
  • 我在运行 gradle build 时遇到错误,无法为 org.gradle.api.Project 类型的根项目“mldata2”获取未知属性“zipFileInput”。

标签: gradle


【解决方案1】:

如果您想访问任务中的项目属性,您需要在项目本身上调用这些属性。

task unzip(type: Copy) {
    doLast {
      def zipFile = file(project.zipFileInput)
      def outputDir = file(project.zipFileOutput)

      from zipTree(zipFile)
      into outputDir
    }
}

【讨论】:

  • 我只想在通过命令行作为参数运行任务时传递值
  • @Ramz 有什么问题?
  • 我需要在我的 jenkins 管道中调用 gradle 任务并传递参数。有可能吗?
猜你喜欢
  • 1970-01-01
  • 2021-08-07
  • 2012-02-20
  • 2020-03-16
  • 2023-03-15
  • 1970-01-01
  • 2016-06-21
  • 2020-10-02
  • 2014-01-09
相关资源
最近更新 更多