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

前端 未结 2 991
情歌与酒
情歌与酒 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 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
    }
    

提交回复
热议问题