Gradle Application Plugin - Building multiple start scripts / dists for the same project with different mainClassName

前端 未结 2 995
情歌与酒
情歌与酒 2021-02-08 21:45

We have a Gradle project using the java plugin that has a couple of command line tools it needs to build. The project is just packaged up into a jar with its dependencies. We\

相关标签:
2条回答
  • 2021-02-08 21:51

    You can always drop down to the task level and declare/configure/wire the necessary tasks yourself, or declare additional tasks on top of what apply plugin: "application" provides. See the application plugin chapter in the Gradle user guide for which related tasks are available.

    0 讨论(0)
  • 2021-02-08 22:17

    Here's one way to generate multiple start scripts with Gradle's application plugin:

    mainClassName = "com.example.PrimaryEntryPoint"
    
    startScripts {
      applicationName = 'primary'
    }
    
    // For convenience, define a map of additional start scripts.
    // Key is script name and value is Java class.
    def extraStartScripts = [
        'secondary' : 'com.example.SecondaryEntryPoint',
        'tertiary'  : 'com.example.TertiaryEntryPoint'
    ]
    
    // Create a task for each additional entry point script.
    extraStartScripts.each { scriptName, driverClass ->
      task(scriptName + "-script",
           group: 'CLI Script Generation',
           type: CreateStartScripts) {
        mainClassName = driverClass
        applicationName = scriptName
        outputDir = startScripts.outputDir
        classpath = startScripts.classpath
      }
    }
    
    // Include the additional start scripts in the distribution
    applicationDistribution.into("bin") {
      from(tasks.withType(CreateStartScripts))
      fileMode = 0755
    }
    
    0 讨论(0)
提交回复
热议问题