gradlebuild.gradlejavacc

How to make ./gradlew buld execute other terminal commands


I am building a gradle project which has a javacc parser file (i.e a file with .jj extension) Therefore, to execute this .jj file we need to run 3 commands in the terminal as javacc filename.jj javac *.java java parsername

However, I want to know how to edit the build.gradle, so that whenever the user enters ./gradlew build all the above mentioned commands would be automatically executed.


Solution

  • Have you consider declaring your own task to do so ?

    task executeCMD(type:Exec) {
      workingDir '.'
      commandLine 'cmd', 'echo', 'Hello world!'
         doLast {
             println "Executed!"
         }
     }
    

    Am not sure how to link with the build command , maybe this can be helpful build.dependsOn project(':ProjectName').task('build') .