在 Gradle 任务中从另一个项目复制文件

Copy file from another project in a Gradle task

给定以下 Gradle 任务:

task copyResource(type: Copy) {
  from('.') {
    include '../anotherProject/password.txt'
  }
  into 'build/docker'
}

在执行任务时忽略包含。从另一个项目目录引用文件的正确方法是什么?

试试这个:

task copyResource(type: Copy) {
  from('../anotherProject') {
    include 'password.txt'
  }
  into 'build/docker'
}

或更简单:

task copyResource(type: Copy) {
  from('../anotherProject/password.txt')
  into 'build/docker'
}