Removed because of security reasons


(java) #1

Removed because of security reasons


(Lance Java) #2

You are making a common mistake of executing logic during the configuration phase rather than the execution phase. You should move your exec and println etc logic into appropriate doFirst { ... } or doLast { ... } blocks


(java) #3

Removed because of security reasons


(Lance Java) #4

I still feel you haven’t fully grasped the concept of the configuration phase and the execution phase. Also note that << is shorthand for doLast so you are trying to configure a doFirst in a doLast block which makes no sense.

I think you want:

task localConfig(type: Copy) {
   def stdout = new ByteArrayOutputStream()
   exec{
      commandLine "hostname", "-s"
      standardOutput = stdout;
   }
   def hostname = new String(stdout.toByteArray()).trim()

   // here we are 'configuring' the copy task
   from "conf/"
   into "build/resources/main/"
   include "deploy-dev.properties"
   include "log4j-dev.properties"
   rename "deploy-dev.properties", "deploy-${hostname}.properties"
   rename "log4j-dev.properties", "log4j-${hostname}.properties"

   doFirst {
      // this will happen just before the copy task's execution
      println "Creating conf/deploy.properties"
      println "Creating conf/log4j.properties"
   }
   doLast {
      // this will happen after the copy task's execution
      assert file("conf/deploy-${hostname}.properties").exists()
      assert file("conf/log4j-${hostname}.properties").exists()
   } 
}


(java) #5

Removed because of security reasons


(Lance Java) #6

I feel you’ve learnt nothing from what I’ve said… I’m sorry but my help stops here.