gradle-如何从战争中排除WEB-INF/classs [英] gradle - how to exclude WEB-INF/classes from war

查看:281
本文介绍了gradle-如何从战争中排除WEB-INF/classs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的要求.我有以下项目布局:

I have a fairly simple requirement. I have the following project layout:

project/build.gradle
 --src/main/java
 --src/main/res

我想做的是为project/src/main/java

将此 jar 文件包含在 war 中,然后将WEB-INF/classes war 文件中排除

Include this jar file in the war and then exclude the WEB-INF/classes from the war file

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'jetty'
apply plugin: 'war'

dependencies {
..
    compile 'com.fasterxml.jackson.core:jackson-core:2.3.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
..
}

jar {
    archiveName = 'hello.jar'
}

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    webInf {
        from ('src/main/res') {
            include '**/*.*'
            into 'resources/'
        }
    }
}


我尝试了各种方法来排除WEB-INF/classes,包括以下代码段:


I have tried various things to exclude WEB-INF/classes including the following snippets:

使用 rootSpec.exclude :

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    rootSpec.exclude ('WEB-INF/classes')
    ...
}

使用 classpath :

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    classpath fileTree(dir:'build/classes/', exclude:'*.class')
    ...
}

('war')使用:

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    from ('war') {
       exclude('WEB-INF/classes')
    }
}

直接进行排除":

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    exclude('WEB-INF/classes')
    ...
}

我在网上找到了所有建议-但似乎都没有用.任何想法我做错了.

Which were all the suggestions I found online - but none of them seems to work. Any ideas what I am doing wrong.

以下是我找到的一些文章和代码的链接: 等级:战争任务具有冲突的包含/排除

Here are links to some of the articles and code I found: Gradle: War Task has Conflicting Includes/Excludes

如何在gradle中排除目录及其内容战争

https://github.com/veny/smevente/blob/master /build.gradle

等级版本为 2.12 .

The gradle version is 2.12.

推荐答案

以下是对我有用的方法,但是您仍然会在战争捆绑包中看到一个(无害的)空包装:

Below is what worked for me, but you will still see an (harmless) empty package in the war bundle:

war {
    rootSpec.exclude('**/com/xxxxx/web/client/')
}

这篇关于gradle-如何从战争中排除WEB-INF/classs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆