Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Using functionality without creating separate task #42

Open
elygre opened this issue Dec 18, 2012 · 2 comments
Open

Using functionality without creating separate task #42

elygre opened this issue Dec 18, 2012 · 2 comments

Comments

@elygre
Copy link

elygre commented Dec 18, 2012

I have a need to run multiple (many) CombineJs and MinifyJs-operations, and would like to not have to create a separate task for each, instead doing something like shown below:

  • I did not find an easier way, but I might be wrong...
  • Would you be interested in adding such functionality (e.g. would you want a pull-request)?
task js2 {
    // This works
    new com.eriwen.gradle.js.JsMinifier().minifyJsFile (
        file("target/build/iknowbase/iknowbase-full.js"),
        [] as Set<File>,
        file("target/build/iknowbase/iknowbase-full.min.js"),
        project.closure.compilerOptions, project.closure.warningLevel, project.closure.compilationLevel
    )
    // Maybe something like this should work?
    com.eriwen.gradle.js.JsMinifier.minifyJs {
        source = file (...)
        dest = file (...)
    }
}
@eriwen
Copy link
Owner

eriwen commented Dec 20, 2012

@elygre Actually, the plugin used to work in such a way that one could specify multiple sets of inputs, but that was too confusing for users so I removed it.

You aren't the first person to bring this up, so perhaps we should write new tasks that accomplish this behavior. I would be more than happy to accept a pull request with suggestions.

If you're not keen on that, here is how you can create tasks dynamically to do what you ask:

javascript.source {
    custom {
        js {
            srcDir "src/js/etc"
            include "*.js"
        }
    }
}

javascript.source.custom.js.files.eachWithIndex { jsFile, idx ->
    tasks.add(name: "dominify${idx}", type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
        source = jsFile
        dest = "${buildDir}/${jsFile.name}"
    }
}
task individualMinify(dependsOn: tasks.matching { Task task -> task.name.startsWith("dominify")})

@elygre
Copy link
Author

elygre commented Dec 20, 2012

My groovy isn't good enough to really know what is the best way of implementing stuff. But, for a start, what do you think about the code at https://gist.github.com/7fb3bda12a0a196e4fd3?

I'm thinking that another way would be to create a function taking only a closure, but I don't know quite how to do that properly...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants