[英]gradle build<ConfigurationName>: different packaging for ear and war (gradle v2.3)
我想使用gradle v2.3配置以兩種方式打包我的應用程序:
如果每次我想要不同的包裝時都修改build.gradle文件,則可以執行這兩項任務中的每一項。 我想使用配置來選擇是否通過使用gradle build<ConfigurationName>
jar包含在war文件中。
基於幫助和StackOverflow帖子如何使用uploadConfigurationName和buildConfigurationName我組成了以下文件(這是一場戰爭):
apply plugin: 'war'
configurations {
packEar
packWar
}
dependencies {
configurations.packEar {
providedCompile project(':Common') // jars will be included using earlib
}
configurations.packWar {
compile project(':Common') // jars included in war
}
}
artifacts {
packWar war
packEar war
}
問題在於gradle buildpackWar
和gradle buildpackEar
命令gradle buildpackWar
產生相等的 戰爭 ,不包含Common
項目中的jar 。 如果我從providerCompile更改packEar的providedCompile
以進行compile
兩者都將與jar產生戰爭。
附加信息:我嘗試使用extendFrom compile / providedCompile
但似乎沒有影響任何事情。 我包括了buildpackWar
和buildpackEar
方法,但是它們也不起作用(可能是因為我以錯誤的方式使用了它們)。
謝謝您的回答!
最好的問候,Ziga
compile
和providedCompile
是自己的配置,所以你要添加的通用項目的,而不是packWar
和packEar
配置。 這樣的事情應該起作用:
mywar
項目 apply plugin: 'war'
apply plugin: 'java'
repositories {
jcenter()
}
configurations {
shareable
}
dependencies {
shareable project(':common')
}
task standaloneWar(type: War, dependsOn: war) {
baseName = war.baseName + '-standalone'
classpath = war.classpath + configurations.shareable
}
artifacts {
archives standaloneWar
}
myear
項目 apply plugin: 'ear'
apply plugin: 'java'
evaluationDependsOn ':mywar'
repositories {
jcenter()
}
dependencies {
deploy project(':mywar')
earlib project(path: ':mywar', configuration: 'shareable')
}
它將產生三個主要工件:
mywar.war
,它不包含shareable
任何依賴項(如common
) mywar-standalone.war
,其中包含shareable
依賴項 myear.ear
,它在根目錄中包含mywar.war
(技術上為mywar.jar
),並在/lib
下的mywar
項目中shareable
的依賴項(例如common
) 使用Ben Navetta提供的信息,我設法產生了一個可行的配置,只需要進行少量調整即可。 這是文件
ACL戰爭
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
configurations {
shareable
publishedWar // need this so war gets placed in ear instead of jar,
// using archives puts both wars in ear
}
dependencies {
providedCompile project(':Common');
shareable project(':Common');
}
war {
baseName = war.baseName + '-thin'
classpath = war.classpath
}
task standaloneWar(type: War, dependsOn: war) {
baseName = project.name // sharable war's name without modifications
classpath = war.classpath + configurations.shareable
}
artifacts {
archives standaloneWar
publishedWar war // to be included in ear
}
注意:
providedCompile project(':Common');
被省略,這將不會編譯 耳
apply plugin: 'ear'
evaluationDependsOn ':ACL' // probably not needed
dependencies {
deploy project(path: ':ACL', configuration: 'publishedWar')
earlib project(path: ':ACL', configuration: 'shareable')
}
ear {
deploymentDescriptor {
webModule ('ACL-thin.war', "${project.name}/ACL") // set context root
}
}
注意:
earlib project(path: ':ACL', configuration: 'shareable')
更改為earlib project(':Common')
否則您將不得不修改eclipse中的部署程序集( 戰爭將包含在其中) Eclipse中 Ear的lib文件夾
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.