我有一个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 '*'
  //    }
  //  }
  //}
}发布于 2021-06-24 19:22:24
您不应该为此使用任务图。另外,您也不应该将该文件下载到src/main/
相反,你应该
例:
tasks.register('remoteResources', Exec) {
   inputs.property('environment', project.property('env')) // this assumes there's a project property named 'env'
   outputs.dir "$buildDir/remoteResources" // point 2 (above)
   commandLine = [
      './scripts/getRemoteResources.sh', 
      '--environment', project.property('env'),
      '--outputdir', "$buildDir/remoteResources"
   ]
   doFirst {
      delete "$buildDir/remoteResources"
      mkdir "$buildDir/remoteResources"
   }
}
processResources {
   from tasks.remoteResources // points 3 & 4 (above)
}请参阅Java插件-任务
processResources -拷贝 将生产资源复制到生产资源目录中。
发布于 2021-06-24 18:16:53
这似乎是可行的,所以我同意,除非有人有更好的解决办法.
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
}https://stackoverflow.com/questions/68120244
复制相似问题