0

Hai everyone currentlly i am confuse on how to invoking an gradle custom task during execution phase, usually invoke by using terminal console "gradle task hello", but now wanna invoke hello task during execution phase each time run the main(string args[]) java method will call the hello task does gradle allow to do that?

I have this code on build.gradle with:

task hello {
  doLast {
     println 'test'
  }
}

gradle.taskGraph.whenReady {
        taskGraph ->
            taskGraph.allTasks.each {
                Task t ->
                   t.dependsOn('hello')
            }
    }
Steven Y.
  • 41
  • 1
  • 6
  • I think you want this https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:finalizer_tasks - but it's not really clear, because your question and your explanation contradict each other? – cfrick Sep 27 '20 at 17:05
  • @cfrick sorry for the confussion currentlly wanna approaching to execute the hello task while every time the java run main method got executed, because our run main method is from java application, the above code "gradle.taskGraph.whenReady" is code when each task has been executed and Main.main() is included on taskgraph but not sure why when t.finalizeBy('Main.main') it doesn't work at all. – Steven Y. Sep 28 '20 at 01:07
  • How do you run your main? application plugin? your own java exec task? – cfrick Sep 28 '20 at 05:11
  • I am running by manually run main method on intelidj IDE and on server is running by trigger the main method from server cron job – Steven Y. Sep 28 '20 at 09:58
  • But for sure not on your server and with a 50/50 chance not in your ide is gradle involved? I think you want a shutdown hook? – cfrick Sep 28 '20 at 10:03
  • previouslly it was from maven project but are migrating into gradle project which run by the java main claiss and the main method. while on intelidj run by click run on the main method to run the java application, is there any way to execute the gradle task when runned the java application? @cfrick – Steven Y. Sep 28 '20 at 11:55
  • Yes, e.g. the application plugin. Then you can `gradle run` your project. Make sure your IDE uses the gradle runner then too. This will not be of any help for running your stuff unless you run it with gradle there too (which is very unlikely) – cfrick Sep 28 '20 at 12:31
  • for running by gradle run, does that will be by commandline gradle run and for intelidj will be from gradle built in task run selection? – Steven Y. Sep 28 '20 at 12:58

0 Answers0