Gradle「アプリケーション」プラグインを使用して、2 番目の mainClass の startScripts を作成したいと考えています。これは可能ですか?アプリケーション プラグインにこの機能が組み込まれていない場合でも、startScripts タスクを利用して、別の mainClass 用に 2 番目のスクリプトのペアを作成することはできますか?
9511 次
3 に答える
14
ルートの 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')
于 2014-05-19T15:57:23.233 に答える
4
タイプの複数のタスクを作成できCreateStartScripts
、各タスクで異なる を設定できますmainClassName
。便宜上、ループでこれを行うことができます。
于 2013-08-25T22:04:01.553 に答える
4
これらの両方の回答の一部を組み合わせて、比較的単純な解決策にたどり着きました。
task otherStartScripts(type: CreateStartScripts) {
description "Creates OS specific scripts to call the 'other' entry point"
classpath = startScripts.classpath
outputDir = startScripts.outputDir
mainClassName = 'some.package.app.Other'
applicationName = 'other'
}
distZip {
baseName = archivesBaseName
classifier = 'app'
//include our extra start script
//this is a bit weird, I'm open to suggestions on how to do this better
into("${baseName}-${version}-${classifier}/bin") {
from otherStartScripts
fileMode = 0755
}
}
アプリケーションプラグインが適用されると、startScripts が作成されます。
于 2014-07-10T21:52:35.377 に答える