Gradle 1.12使用者指南翻譯——第二十七章. Ear 外掛程式,gradle1.12
其他章節的翻譯請參見:
http://blog.csdn.net/column/details/gradle-translation.html
翻譯項目請關注Github上的地址:
https://github.com/msdx/gradledoc/tree/1.12。
直接瀏覽雙語版的文檔請訪問:
http://gradledoc.qiniudn.com/1.12/userguide/userguide.html。
另外,Android 手機使用者可通過我寫的一個程式瀏覽文檔,帶緩衝功能的,目前0.2版本相容2.1以上(5.0沒試過)的Android系統,地址如下:
http://www.wandoujia.com/apps/com.githang.gradledoc
翻譯不易,轉載請註明本文在CSDN部落格上的出處:
http://blog.csdn.net/maosidiaoxian/article/details/45530583
關於我對Gradle的翻譯,以Github上的項目及http://gradledoc.qiniudn.com 上的文檔為準。如有發現翻譯有誤的地方,將首先在以上兩個地方更新。因時間精力問題,部落格中發表的譯文基本不會同步修改。
第二十七章. Ear 外掛程式
Ear 外掛程式添加了用於組裝 web 應用程式的 EAR 檔案的支援。它添加了一個預設的EAR archive task。它不需要 Java 外掛程式,但是對於使用了 Java 外掛程式的項目,它將禁用預設的 JAR archive 的產生。
27.1. 用法
要使用 Ear 的外掛程式,請在構建指令碼中包含以下語句:
樣本 27.1. 使用 Ear 外掛程式
build.gradle
apply plugin: 'ear'
27.2. Tasks
Ear 外掛程式向project 中添加了以下任務。
表 27.1. Ear 外掛程式 - tasks
| 任務名稱 |
依賴於 |
類型 |
描述 |
ear |
compile(僅在也配置了使用 Java 外掛程式的時候) |
ear |
組裝應用程式 EAR 檔案。 |
Ear 外掛程式向基礎外掛程式所加入的 tasks 添加了以下的依賴。
表 27.2. Ear 外掛程式 - 額外的task 依賴
27.3. 項目布局
表 27.3. Ear 外掛程式 - 項目布局
| 目錄 |
意義 |
src/main/application |
Ear 資源,如 META-INF 目錄 |
27.4. 依賴管理
Ear 外掛程式添加了兩個依賴配置:deploy和earlib。所有在deploy配置中的依賴項都放在 EAR 檔案的根目錄中,並且是不可傳遞的。所有在 earlib 配置的依賴都放在 EAR 檔案的“lib”目錄中,並且是 可 傳遞的。
27.5. 公約屬性
表27.4. Ear外掛程式 - 目錄屬性
| 屬性名稱 |
類型 |
預設值 |
描述 |
appDirName |
String |
src/main/application |
相對於項目目錄的應用程式來源目錄名稱。 |
libDirName |
String |
into(<s2>'libs'</s2>) { |
產生的 EAR 檔案裡的 lib 目錄名稱。 |
deploymentDescriptor |
org.gradle.plugins.ear.descriptor.DeploymentDescriptor |
部署描述符,它有一個合理的名為application.xml的預設值 |
用於產生部署描述符檔案的中繼資料,例如application.xml。如果此檔案已存在於appDirName/META-INF,那麼會使用這個已存在的檔案的內容,而ear.deploymentDescriptor中的顯式配置將被忽略。 |
這些屬性由一個EarPluginConvention 公約對象提供。
27.6. Ear
Ear task 的預設行為是將src/main/application的內容複寫到archive 的根目錄下。如果你的application目錄沒有包含META-INF/application.xml部署描述符,那麼將會為你產生一個。
另請參閱 Ear。
27.7. 自訂
下面是一個樣本,展示了最重要的自訂選項:
樣本 26.2. ear 外掛程式的自訂
build.gradle
apply plugin: 'ear'apply plugin: 'java'repositories { mavenCentral() }dependencies { //following dependencies will become the ear modules and placed in the ear root deploy project(':war') //following dependencies will become ear libs and placed in a dir configured via libDirName property earlib group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'}ear { appDirName 'src/main/app' // use application metadata found in this folder libDirName 'APP-INF/lib' // put dependency libraries into APP-INF/lib inside the generated EAR; // also modify the generated deployment descriptor accordingly deploymentDescriptor { // custom entries for application.xml:// fileName = "application.xml" // same as the default value// version = "6" // same as the default value applicationName = "customear" initializeInOrder = true displayName = "Custom Ear" // defaults to project.name description = "My customized EAR for the Gradle documentation" // defaults to project.description// libraryDirectory = "APP-INF/lib" // not needed, because setting libDirName above did this for us// module("my.jar", "java") // wouldn't deploy since my.jar isn't a deploy dependency// webModule("my.war", "/") // wouldn't deploy since my.war isn't a deploy dependency securityRole "admin" securityRole "superadmin" withXml { provider -> // add a custom node to the XML provider.asNode().appendNode("data-source", "my/data/source") } }}
你還可以使用Ear任務提供的自訂選項,如from和metaInf。
27.8. 使用自訂的描述符檔案
假設你已經有了application.xml ,並且想要使用它而不是去配置ear.deploymentDescriptor程式碼片段。去把 META-INF/application.xml 放在你的源檔案夾裡的正確的位置(請查看 appDirName 屬性)。這個已存在的檔案的內容將會被使用,而 ear.deploymentDescriptor 裡的顯示配置則會被忽略。