8

我有一个带有战争规范的子项目,如下所示:

war {
    from('resources')  {
        include '*.properties'
        into 'WEB-INF/classes/'
    }    
    webXml = file('src/main/webapp/WEB-INF/web.xml')
}

效果很好。创建可部署到 Tomcat 的单个胖战争文件。问题是,在部署到 TomEE 和 JBoss 时,我遇到了冲突(即与 Javax Servlet、Jersey 等)。所以我想排除一组罐子被战争。我查看了 Gradle 战争文档,看起来我需要为此使用排除项。我尝试了两种不同的方式,并且罐子没有被排除在战争之外:

war {

    // copy properties file in classes so that 
    // they may be loaded from classpath
    from('resources')  {
        include '*.properties'
        into 'WEB-INF/classes/'
    }

    // specify web xml
    webXml = file('src/main/webapp/WEB-INF/web.xml')

    // remove jars that conflict with TomEE
    exclude '**/javax.inject-1.jar'
    exclude '**/javax.servlet-2.5.0.v201103041518.jar'
    exclude '**/servlet-api-2.5.jar'
    exclude '**/validation-api-1.0.0.GA.jar'

}

这是在 github 上托管的 NetFlix/karyon 项目的一个子项目(karyon-examples)中。子项目中的依赖项如下所示:

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.0'
    runtime 'org.slf4j:slf4j-simple:1.7.0'
    compile project(':karyon-extensions')
    compile project(':karyon-admin-web')
}

而且我想避免编辑诸如编译与运行时依赖项之类的东西,尤其是在其他文件和子项目中。事实上,我在上面试图排除的罐子在使用码头和常规 tomcat 运行时是良性的。

我只是想在不使构建脚本复杂化的情况下排除这些 jar。我错过了什么?

谢谢

4

2 回答 2

9

the obvious way to go is to move the dependencies you don't want to have in your war from the compile configuration to providedCompile and from runtime to providedRuntime. the provided configurations are added to your build when the war plugin is applied.

One other note on your snippet above: I think the exclude does not work because you referencing the target path in your exclude statements instead you should just reference it by /servlet-api-2.5.jar.

于 2013-04-05T20:33:26.477 回答
0

你可以这样

dependencies {
  compile fileTree(dir: 'WebContent/WEB-INF/lib', include: ['*.jar'])
  compile("org.apache.tomcat:tomcat-jni:8.0.37")
  providedRuntime("org.apache.tomcat:tomcat-jni:8.0.37")

}

于 2016-10-28T06:13:52.940 回答