1

I have created a plugin for Gradle to deploy to my company's OpenVMS directory structures, which adds deployDev, deployTest, and, when credentials are provided, deployProd tasks to an application build. I have extracted our configuration files for all environments to a separate project so that we can deploy configuration separately from the application.

These custom tasks depend on the application plugin's distZip task and I haven't found a good way to get the appropriate configuration files into the zip based on the called task (e.g. deployDev includes dev config).

I have tried having the deploy* tasks copy configuration files during the configuration phase with:

task distZip(type:Zip, overwrite:true) {
   archiveName = 'config.zip'
   from "build/props"
}

deployDev.configure {
    copyResources('dev')
}

deployTest.configure {
    copyResources('test')
}

project.tasks.findByName('deployProd')?.configure {
    copyResources('prod')
}

def copyResources(String environment){
    copy {
        from "src/$environment/resources"
        into 'build/props'
    }
}

This doesn't work due to configuration phase executing on all tasks, so even when we execute deployDev, the test configuration has been copied over the dev resources.

I also have tried:

file('build/props').mkdirs()

task distZip(type:Zip, overwrite:true) {
   archiveName = 'config.zip'
   from "build/props"
   outputs.upToDateWhen {false}
}

gradle.taskGraph.whenReady { graph ->
   if (graph.hasTask('deployProd')) {
       copyResources('prod')
   }else if(graph.hasTask('deployTest')){
       copyResources('test')
   }else if(graph.hasTask('deployDev')){
      copyResources('dev')
   }
}


def copyResources(String environment){
   copy {
        from "src/$environment/resources"
        into 'build/props'
    }
}

However, with this proposal the distZip task always is UP-TO-DATE. Is there a correct way to do this?

Jordan Grant
  • 860
  • 7
  • 12
  • 2
    You say "These custom tasks depend on the application plugin's distZip task", but in fact you overwrite that task. Why? Also, what do the deploy tasks do, other than adding resources to the distribution zip? – Peter Niederwieser Jan 16 '13 at 20:53
  • I overwrite distZip in this particular build, but most of our applications can use my plugin without overwriting the task. I must admit, I do not remember why I overwrote the task and so I will change the build to only configure distZip. The purpose of the deploy tasks is actually to move the output of distZip to our OpenVMS servers (dev, test, or prod) and deploy the distribution, which usually is an application, but in this case is just the application configuration. – Jordan Grant Jan 16 '13 at 21:54
  • Perhaps I overwrote the task to avoid calling the `compileJava`,`processResources`,`classes`,`jar`,`startScripts` tasks, but they don't seem to hurt anything. In fact, I may be able to use the processResources task to achieve what I need, so I'm going to try that. – Jordan Grant Jan 16 '13 at 22:07

0 Answers0