首页 > 解决方案 > Gradle JAR 创建时间

问题描述

我有一个 gradle 构建,它可以检索属性文件,并且这些文件是远程的(将密码保存在 github 之外),但是在构建 JAR 时远程检索还没有完成。

我想我要么必须在执行阶段而不是配置阶段创建 JAR,要么在执行阶段添加远程文件,但我无法工作。

有什么建议么?

task fatJar(type: Jar) {

  doFirst {
    exec {
      executable './scripts/getRemoteResources.sh'
    }
  }

  ...

  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) 
  }

  //some resources are retrieved remotely & b/c of timing they don't get included here
  from ('src/main/java/resources') {
    include '*'
  }

  with jar

  //tried this but doesn't work
  //doLast {
  //  jar {
  //    from ('src/main/java/resources') {
  //      include '*'
  //    }
  //  }
  //}


}

标签: gradlejartiming

解决方案


这似乎可行,所以除非有人有更好的解决方案,否则我将继续使用它...

gradle.taskGraph.beforeTask { Task task ->

  println "just before $task.name"

  // i just chose to kick this off with the first task sent through here
  if (task.name=="compileJava") {
    exec {
      executable './scripts/getRemoteResources.sh'
    }
  }
}
      


task fatJar(type: Jar) {

  ...

  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) 
  }

  from ('src/main/java/resources') {
    include '*'
  }

  with jar

}

推荐阅读