我正在尝试插件:

  • io.freefair.war-overlay-只是将一场 war 叠加到另一场
  • waroverlay-它具有适当的选项“includeWarJars true”,但它
    对我不起作用。

  • 目前,我正在尝试编写脚本:
    dependencies {
        /* jar, his files I would like to include in war */
        compile project(':my_jar_1')
    }
    
    war {
    
        /* Step 1. Copy all from my_jar_1 into WEB-INF/classes */
    
        into('WEB-INF/classes') {
            from configurations.compile
                    .filter { it.name.startsWith("my_jar_1") }
                    .collect { zipTree(it).matching { exclude 'META-INF/**/*.*' }}
        }
    
        /* Step 2. Deleting jar from war WEB-INF/lib. I got stuck here. It println, but doesn't delete jar */
    
        doLast {
            zipTree('build/libs/war_1-0.0.0.war').files.each {
                if (it.path.endsWith('.jar')) {
                    delete it
                    println 'DELETED ' + it.path
                }
            }
        }
    }
    

    有人可以告诉我如何使其工作吗?
    还是smb知道更优雅的解决方案?

    我也在尝试声明自己的配置
    configurations { overlay }
    dependencies {
        overlay project(':my_jar_1')
    }
    war {
            into('WEB-INF/classes') {
                from configurations.overlay
                ...
    

    但是显示错误

    最佳答案

    WEB-INF/libWEB-INF/classes的内容由classpath任务的单个属性war配置。根据文档:



    因此,在您的情况下,应将classpath修改如下

    war {
        def myJar = project(':my_jar_1').jar.outputs
        def myClassesAndResources = project(':my_jar_1').sourceSets.main.output
        classpath = classpath - myJar + myClassesAndResources
    }
    

    关于gradle - 如何使用Gradle将Jar中的所有文件包含到 war 中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45240654/

    10-11 12:17