2013-08-24 7 views
15

2番目のmainClassのstartScriptsを作成するためにGradle "application"プラグインを使用したいと思います。これは可能ですか?アプリケーションプラグインにこの機能が組み込まれていなくても、startScriptsタスクを利用して別のmainClass用のスクリプトを作成することは可能ですか?gradle 'application'プラグインを使用して複数のメインクラスを指定することは可能ですか

+0

この回答を見る:http://stackoverflow.com/questions/21241767/multiple-startscript-using-gradle-for-heroku – Phil

答えて

4

タイプCreateStartScriptsの複数のタスクを作成することができ、それぞれのタスクで別のmainClassNameを構成することができます。便宜上、これをループで行うことができます。

+3

既存のコードはありますか?ドキュメンテーションは、同時に私たちがgroovyとgradleを学ぶ人たちのために、これを「ループで」行う方法を説明する良い仕事を単純にしません。 – Core

10

ルート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.runtime 
    } 
    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') 
+2

プログラムのコマンドライン引数を設定する起動スクリプトを作成できますか? –

3

私はこれらの答えの両方の部品を組み合わせました比較的簡単な解決法に到達する:

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は、アプリケーションationプラグインが適用されます。

+0

applicationDistribution.from(otherStartScripts){into 'bin'}について – Joel

関連する問題