Gradle Application Plugin - Create multiple startup scripts / disks for the same project using another mainClassName

We have a Gradle project using a java plugin in which there are several command line tools that need to be built. The project is simply packaged in a jar with its dependencies. Then we would like for several start scripts to run different entry points in this project for each of these tools.

Naturally, the plugin app is a good choice. And so we changed java to the application and provided mainClassName for creating startup scripts and tar distributable. This worked to create a single application bank, but only one set of startup scripts that used the specified name mainClassName.

How can we create several start scripts for different entry points? (different mainClassName 's?)

One approach that I tried was to create some subprojects in which the application plugin was applied, and separately define the individual names mainClassNames

 allprojects { apply plugin: 'java' repositories { // maven repos } dependencies { compile 'com.thirdparty:somejar:1.0' } sourceCompatibility = 1.7 } subprojects { apply plugin: 'application' } project(':tools:csvLoader') { mainClassName = 'com.demo.tools.csvLoader.Loader' } project(':tools:summariser') { mainClassName = 'com.demo.tools.summary.Summarise' } 

And indicated in the settings of the root projects .gradle

 include "tools","tools:csvLoader","tools:summariser" 

This worked - but each subproject creates an identical jar (just named with the name of the subproject), and each subdir assembly folder stores a copy of that jar plus one more copy of all the dependencies. This is a bit wasteful. It can also be misleading to a new developer who sees subprojects there with all these tasks and without code.

Is there a better way to tell Gradle about performing several tasks related to the application, but changing the name mainClassName for each without having to resort to creating empty subprojects?

Thanks!

+8
gradle
source share
1 answer

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

+2
source share

All Articles