Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在多项目gradle构建中,如何将子项目-a.war的内容打包到子项目-B.jar中_Java_Tomcat_Gradle_Build.gradle_Multi Project - Fatal编程技术网

Java 在多项目gradle构建中,如何将子项目-a.war的内容打包到子项目-B.jar中

Java 在多项目gradle构建中,如何将子项目-a.war的内容打包到子项目-B.jar中,java,tomcat,gradle,build.gradle,multi-project,Java,Tomcat,Gradle,Build.gradle,Multi Project,问题:给定以下多项目gradle构建 superproject subproject-A -> war subproject-B -> jar 我正在寻找一种方法来配置subproject-B以解压缩subproject-a生成的war的内容,并将解压缩的webapp目录的内容(将用于部署的类和资源放入容器中)打包到根级别的子项目B的应用程序分发版中,以及后者的类、资源和依赖项。因此,为子项目-B生成的分发结构应如下所示: subproject-B-0.1.0

问题:给定以下多项目
gradle
构建

superproject
    subproject-A -> war
    subproject-B -> jar
我正在寻找一种方法来配置
subproject-B
以解压缩
subproject-a
生成的
war
的内容,并将解压缩的
webapp
目录的内容(将用于部署的类和资源放入容器中)打包到根级别的
子项目B
的应用程序分发版中,以及后者的类、资源和依赖项。因此,为
子项目-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)
子项目-B-0.1.0
bin/。。。
解放党/

META-INF/(我终于找到了一个解决方案,因此将其发布在这里,以方便那些面临类似问题的人:

子项目/build.gradle

子项目b/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)
}
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/**'
}