0

I am trying to create a Grails plugin that creates a custom Gradle Task which can be depended on by bootRun. I would like to do something like this:

     @CompileStatic
static void configureProcessConfig(Project project) {
    TaskContainer taskContainer = project.tasks
    if(taskContainer.findByName('processConfig') == null) {
        taskContainer.create("processConfig") {
            List<File> testResources = [project.file("src/test/resources")]
            for (t in testResources) {
                if (t.name.contains('.properties') || t.name.contains('.groovy')) {
                    Path originFile = t.toPath()
                    Path destFile = Paths.get('build/classes/main/' + t.name)
                    Files.copy(originFile, destFile)
                }
            }
        }
        def processConfigTask = taskContainer.findByName('processConfig')
        taskContainer.findByName("bootRun")?.dependsOn(processConfigTask)
    }
}

However, I can't seem to get it to work in my xxxGrailsPlugin.groovy file. I don't know where to get the Project file to call this. It doesn't create the task. I am happy to do something different, but I can't figure out how to do it. I would prefer not to write to every build.gradle file where this plugin is used, but if that's the best option, I guess I will.

Any help is appreciated. Thanks!

javatami
  • 18
  • 5
  • To make a custom, reusable task, try part IV of the gradle guide . But I think the objective you are trying to reach is already covered by the gradle Java Plugin. See the gradle guide chapter on that plugin, specifically the section on working with source sets. Since the guide gets reorganized from time to time, I'm only giving the main link: https://docs.gradle.org/current/userguide – npskirk Dec 02 '16 at 15:43
  • @npskirk Thanks for your comment. I was looking in the grails documentation for ways to do this, but it appears the gradle documentation is much better. – javatami Dec 02 '16 at 16:05

0 Answers0