2015-09-12 27 views
0

問題:鑑於以下多項目gradle構建在多項目建設的gradle我怎麼收拾子項目 - A.war的內容轉換成子項目,B.jar

superproject 
    subproject-A -> war 
    subproject-B -> jar 

我正在尋找一種方法來配置subproject-B來解壓由subproject-A產生的war的內容和有解壓webapp目錄的內容(與類和資源部署到一個容器)裝入在subproject-B應用程序分發根級以及後者的類別,資源和依賴關係。因此,對於subproject-B生產分佈的結構應該是這樣的:

subproject-B-0.1.0 
    bin/... 
    lib/ 
     META-INF/ (<-- from B) 
     WEB-INF/ (<-- from A.war) 
     css/  (<-- from A.war) 
     js/  (<-- from A.war) 
     *.jar  (code and dependencies of B) 

得到的回答here從A複製資源B的問題。在這裏,我需要複製一個動態生成的構建工件的內容(並且通常可以將其複製到main/resources中,因爲後者將打包到jar中)。

的理由:subproject-B是運行Tomcat的嵌入服務器的JavaFX的WebView訪問的subproject-B Web應用程序上本地主機打開,否則網絡應用程序轉換一種的一個獨立的Java應用程序獨立的桌面應用程序。這是20行代碼在Eclipse中很好地運行,但似乎構成分發的包裝挑戰。

回答

0

我終於找到了一個解決方案,以便張貼在這裏爲那些面臨着類似的問題的好處:

subprojectA/build.gradle

apply plugin: "java" 
apply plugin: "war" 

archivesBaseName = "subprojectA" 

sourceCompatibility = 1.8 
compileJava.options.encoding = "utf-8" 

war { 
    manifest { 
     archiveName = "$baseName.$extension" 
     attributes "Implementation-Title": archivesBaseName, 
        "Implementation-Version": version 
    } 
} 

// declare configuration to refer to in superprojectB 
configurations { 
    subprojectAwar 
} 
// make this configuration deliver the generated war 
dependencies { 
    subprojectAwar files(war.archivePath) 
} 

subprojectB/build.gradle

apply plugin: "java" 
apply plugin: 'application' 

archivesBaseName = "subprojectB" 

sourceCompatibility = 1.8 
compileJava.options.encoding = "utf-8" 

// declare configuration to take files from 
configurations { 
    subprojectAwar 
} 

dependencies { 
    // bind the configuration to the respective configuration in subprojectA 
    subprojectAwar project(path: ":subprojectA", configuration: "subprojectAwar") 

    compile "org.apache.tomcat.embed:tomcat-embed-core:$tomcatEmbedVersion" 
    compile "org.apache.tomcat.embed:tomcat-embed-websocket:$tomcatEmbedVersion" 
    compile "org.apache.tomcat.embed:tomcat-embed-logging-log4j:$tomcatEmbedVersion" 
    compile "org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatEmbedVersion" 
} 

mainClassName = 'org.project.subprojectB.StartServer' 

jar { 
    // make sure this project is assembled after the war is generated 
    dependsOn(":subprojectA:assemble") 

    manifest { 
     archiveName = "$baseName.$extension" 
     attributes "Implementation-Title": archivesBaseName, 
        "Implementation-Version": version 
     attributes 'Main-Class': '$mainClassName' 
    } 
    // if you need to copy the content of the war into the jar: 
    // (otherwise only to the distribution, see below) 
    /* 
    from(zipTree(configurations.subprojectAwar.collect { it }[0])) { 
     into "" 
     exclude '**/META-INF/**' 
    } 
    */ 
} 

// copy the content of the war excluding META-INF into the lib of superprojectB 
applicationDistribution.from(zipTree(configurations.subprojectAwar.collect { it }[0])) { 
    into "lib" 
    exclude '**/META-INF/**' 
} 
相關問題