gpt4 book ai didi

java - 是否可以使用 gradle 'application' 插件指定多个主类

转载 作者:太空狗 更新时间:2023-10-29 22:40:01 26 4
gpt4 key购买 nike

我想使用 Gradle“应用程序”插件为第二个 mainClass 创建 startScripts。这可能吗?即使应用程序插件没有内置此功能,是否可以利用 startScripts 任务为不同的 mainClass 创建第二对脚本?

最佳答案

将类似这样的内容添加到您的根 build.gradle:

// Creates scripts for entry points
// Subproject must apply application plugin to be able to call this method.
def createScript(project, mainClass, name) {
project.tasks.create(name: name, type: CreateStartScripts) {
outputDir = new File(project.buildDir, 'scripts')
mainClassName = mainClass
applicationName = name
classpath = project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtimeClasspath
}
project.tasks[name].dependsOn(project.jar)

project.applicationDistribution.with {
into("bin") {
from(project.tasks[name])
fileMode = 0755
}
}
}

然后从根项目或子项目中按如下方式调用它:

// The next two lines disable the tasks for the primary main which by default
// generates a script with a name matching the project name.
// You can leave them enabled but if so you'll need to define mainClassName
// And you'll be creating your application scripts two different ways which
// could lead to confusion
startScripts.enabled = false
run.enabled = false

// Call this for each Main class you want to expose with an app script
createScript(project, 'com.foo.MyDriver', 'driver')

关于java - 是否可以使用 gradle 'application' 插件指定多个主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18421857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com