Thank you Adam. Forgive me to bring this simple question into a discussion.
I beg to disagree. How can it not be a task? Who decides? Me or Gradle? (this sounds Maven-y) Actually it is similar to Exec(Task) and project.exec are used. Exec can be used either way. Why can't our own tasks be like that? Since Exec is the role model in this regard, I've tried to look at project.exec's implementation. I was expecting a simple wrapper of Exec task, but it's not. It actually has several redirections and in the end I'm not sure if it actually uses Exec task at all. I thought the purpose of custom tasks is to make them reusable? Suppose the custom task is already packaged into a JAR (i.e. Like custom Ant tasks), how can I use them without disassembling the JAR (which let's suppose I dont have source access to)? One reason why prefer custom Gradle tasks instead of regular Groovy methods/classes is they use Gradle conventions. When using Groovy methods I have to pass the "parent" task or project, and the usage is not "standardized". Thank you. On 1/10/11, Adam Murdoch-3 [via Gradle] <[email protected]> wrote: > > > > On 08/01/2011, at 7:28 PM, Hendy Irawan wrote: > >> >> I'm trying to run a custom task from inside a regular task. >> >> My custom task is: >> >> class SshTask extends DefaultTask { >> String user >> String host >> String command >> >> @TaskAction >> void run() { >> project.exec { >> commandLine 'ssh', "$u...@$host", command >> } >> } >> } >> >> My regular task is : >> >> task deploy { >> description = 'Deploy the download to remote server. Specify $user, >> $host, >> and $deploymentDir.' >> doLast { >> ssh = new SshTask() >> ssh.configure { >> user = server.user >> host = server.host >> command = "mkdir -vp $server.dir" >> } >> ssh.execute() >> } >> } >> > > It's not really a task if you plan to use it this way - it's just a regular > class. You can get rid of the 'extends DefaultTask' from SshTask. > > > -- > Adam Murdoch > Gradle Developer > http://www.gradle.org > CTO, Gradle Inc. - Gradle Training, Support, Consulting > http://www.gradle.biz > > > > ______________________________________ > View message @ > http://gradle.1045684.n5.nabble.com/How-to-run-ad-hoc-anonymous-task-without-naming-the-task-tp3332909p3334340.html > > To unsubscribe from How to run "ad hoc"/anonymous task (without > naming the task), visit > http://gradle.1045684.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3332909&code=aGVuZHlAc29sdXZhcy5jb218MzMzMjkwOXwxNTI0Njc4NzUy -- Sent from my mobile device Hendy Irawan www.CariDuitInternet.com www.HendyIrawan.com ----- http://www.HendyIrawan.com -- View this message in context: http://gradle.1045684.n5.nabble.com/How-to-run-ad-hoc-anonymous-task-without-naming-the-task-tp3332909p3334397.html Sent from the gradle-user mailing list archive at Nabble.com.
