What is the gradle equivalent of maven's exec plugin for running Java apps?

前端 未结 2 734
慢半拍i
慢半拍i 2021-01-03 19:03

With maven I can create a project, set up my pom with its dependencies, write a class with a main method and then to run it type:

mvn compile exec:java -Dexe         


        
2条回答
  •  既然无缘
    2021-01-03 19:45

    The easiest solution is to use the Application Plugin, which among other things provides a run task. To make the main class configurable from the command line, you'll have to set mainClassName to the value of some system (or project) property, and then pass that property from the command line:

    apply plugin: "application"
    
    mainClassName = System.getProperty("mainClass")
    

    Now you can run the application with gradle run -DmainClass=thornydev.App.

提交回复
热议问题