Gradle应用程序插件-为具有不同mainClassName的同一项目构建多个启动脚本/dist [英] Gradle Application Plugin - Building multiple start scripts / dists for the same project with different mainClassName

查看:273
本文介绍了Gradle应用程序插件-为具有不同mainClassName的同一项目构建多个启动脚本/dist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Java插件的Gradle项目,该项目具有一些需要构建的命令行工具.该项目只是与它的依赖关系一起打包到一个jar中.然后,我们希望使用几个启动脚本为这些工具中的每个工具启动该项目中的各个入口点.

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'd then like a couple of start scripts to kick off the various entry points in that project for each of these tools.

当然, application 插件是一个不错的选择.因此,我们将 java 更改为 application ,并提供了mainClassName来创建启动脚本和可分发的tar.这样可以创建一个应用程序jar,但是只有一组使用指定的 mainClassName 的启动脚本.

Naturally the application plugin is a good choice. And so we changed java to application and provided a mainClassName to create start scripts and tar distributable's. This worked to create a single application jar, but only one set of start scripts that used the mainClassName specified.

我们如何为不同的入口点创建多个启动脚本? (不同的mainClassName?)

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

我尝试的一种方法是创建一些子项目,这些子项目应用了 application 插件,并分别指定了各个mainClassNames

One approach I tried was creating some subprojects that had the application plugin applied and specified the individual mainClassNames seperatately

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'
}

并在根项目的settings.gradle中引用

And referenced in the root projects settings.gradle

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

这有效-但是每个子项目都创建一个相同的jar(仅以子项目的名称命名),每个subdir构建文件夹都包含该jar的副本以及所有依赖项的另一个副本.那感觉有点浪费.对于新开发人员来说,在那里看到带有所有这些任务且没有任何代码的子项目,也可能会造成混乱.

This worked - but each subproject creates an identical jar (just named with the name of the subproject) and each subdir build folder holds a copy of that jar plus another copy of all the dependencies. Thats feels a little wasteful. It could also be confusing to a new developer seeing the subprojects there with all these tasks and no code whatsoever.

是否有更好的办法告诉gradle进行多个与应用程序相关的任务,但是无需为创建空子项目而更改每一个的mainClassName?

Is there a better way go about telling gradle to make multiple application related tasks but changing the mainClassName for each without having to resort to creating empty subprojects?

谢谢!

推荐答案

您始终可以下拉至任务级别,自己声明/配置/连接必要的任务,或者在apply plugin: "application"提供的内容之上声明其他任务.请参阅Gradle用户指南中与相关的应用程序插件一章.任务可用.

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.

这篇关于Gradle应用程序插件-为具有不同mainClassName的同一项目构建多个启动脚本/dist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆