2013-08-24 24 views
15

'u kullanarak birden fazla ana sınıf belirtmek mümkün olabilir İkinci bir ana sınıf için startScripts oluşturmak için Gradle "application" eklentisini kullanmak istiyorum. Mümkün mü? Uygulama eklentisi yerleşik olarak bu işlevselliğe sahip olmasa bile, farklı bir mainClass için ikinci bir betik çifti oluşturmak için startScripts görevinden yararlanmak mümkün müdür?Not 'uygulama' eklentisi

+0

Bu cevabı bakın: http://stackoverflow.com/questions/21241767/multiple-startscript-using-gradle-for-heroku – Phil

cevap

4

CreateStartScripts türünde birden çok görev oluşturabilir ve her bir görevde farklı bir mainClassName yapılandırabilirsiniz. rahatlık için bunu bir döngüde yapabilirsiniz. Sonra

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

kökünden veya alt projenin ya şöyle diyoruz:

+3

Orada mevcut herhangi bir kod var mı? Dokümantasyon, aynı zamanda, mükemmel bir şekilde öğrenmemiz ve aynı zamanda eğitim almamız için bunu 'döngü içinde' nasıl yapacağınızı açıklayan iyi bir iş yapmaz. – Core

10

kök build.gradle için böyle bir şey ekle

// 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

Programın komut satırı argümanlarını ayarlayan bir başlangıç ​​komut dosyası oluşturabilir miyiz? –

3

Ben bu cevapların her iki bölümlerini kombine göreceli olarak basit bir çözüme varmak için:

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, uygulandığında oluşturulur ation eklentisi uygulanır.

+0

applicationDistribution.from (otherStartScripts) {into 'bin'} hakkında ne dersiniz – Joel