2013-08-28 35 views
0

我使用Gradle的應用程序插件爲我的應用程序捆綁了一個運行庫,其中包括啓動所需的庫和shell腳本。這是下面所有做工精細:Gradle應用程序插件:需要在發行版中包含src

apply plugin: 'groovy' 
apply plugin: 'application' 

applicationName = "appName" 
mainClassName = 'com.myApp.cli.ScriptRunner' 

buildDir = "${System.properties['user.home']}/.myApp/build" 
archivesBaseName = 'myApp' 
version = "1.0" 
group = 'myApp' 

sourceSets { 
    main { 
    groovy { 
     srcDir 'src/groovy' 
     exclude '**/web/**' 
    } 
    java { 
     srcDir 'src/java' 
    } 

    } 
} 

startScripts { 
    classpath = files('$APP_HOME/lib/*') 
} 


repositories { 
    mavenCentral() 
} 


dependencies { 
    // dependencies omitted for brevity 
} 

我發現from here,我可以使用applicationDistribution包括其他文件。我遇到的問題是如何告訴它我需要哪些文件。我嘗試以下認爲這是正確的做法:

task copySrc(type:Copy) { 
    from('src/groovy/com/myApp/receiver') { 
    include '**/*.groovy' 
    } 
    into "$buildDir/src" 
} 

task createSrc { 
    def src = file("$buildDir/src") 
    outputs.dir src 
    doLast { 
    src.mkdirs() 
    copySrc 
    } 
} 

applicationDistribution.from(createSrc) { 
    into "src" 
} 

不過,我從來沒有看到copySrc得到打來電話,我甚至不知道這是可能的。歡迎提出建議。

回答

2

我想通了。我可以從applicationDistribution中調用copySrc。

task copySrc(type:Copy) { 
    from('src/groovy/com/myApp/receiver') { 
    include '**/*.groovy' 
    } 
    into "$buildDir/src" 
} 

applicationDistribution.from(copySrc) { 
    into "src" 
} 
1

這是一個更容易一點:

applicationDistribution.from("${rootProject.projectDir}/") { 
    include "README.md", "LICENSE.md" 
} 
+0

這是記錄任何地方? – Gregg

+0

http://www.gradle.org/docs/current/groovydoc/org/gradle/api/plugins/ApplicationPluginConvention.html – binwiederhier

相關問題