如何从WEB-INF / lib中排除特定的jar [英] How to exclude specific jars from WEB-INF/lib

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

问题描述

  jar-module-A 
+ - JavaEE lib(Dependency) )

war-module-A
+ - jar-module -A

我想从WEB-INF / lib中排除JavaEE库。


  1. 使用providedCompile:



    由于jar-module-A不是web模块,而是jar,所以我不能在build.gradle jar-module-A中使用provideCompile。


  2. 配置{runtime.exclude JavaEE-lib}

    它不仅将JavaEE从运行时中排除,而且还排除了testRuntime,它在战争中的单元测试失败如何缓解这种情况?


  3. 解决方案 解决方案将是:

      apply plugin:'java'
    apply plugin:'war'
    apply plugin:'maven'

    repositories {
    mavenCentral()
    maven {
    urlfile:/// tmp / repo

    }

    uploadArchives {
    repositories {
    mavenDeployer {
    repository(url:file:/// tmp / repo)
    }
    }
    }

    依赖关系{
    编译组:'ruimo',名称:'module_a',版本:'1.0 -SNAPSHOT'
    testCompile组:'junit',名称:'junit',版本:'4.10'
    }

    war {
    classpath = classpath.filter {
    it.name!='javaee-api-6.0.jar'
    }
    }

    用于 module_b 。它可能是文件名依赖(不确定)。也许稍后会看看,但不确定 - 与时间短。



    更新



    更复杂:

      apply plugin:'java'
    apply plugin:'war'
    申请插件:'maven'

    知识库{
    mavenCentral()
    maven {
    urlfile:/// tmp / repo
    }

    $ b uploadArchives {
    repositories {
    mavenDeployer {
    repository(url:file:/// tmp / repo)
    }

    $ b编译(group:'ruimo',name:'module_a',版本:'1.0-SNAPSHOT'){
    transitive = false //这里你可以排除特定的依赖关系,不一定全是
    }
    provideCompile组:'javax',name:'javaee-api',版本:'6.0'
    testCompile group:'junit',name:'junit',version:'4.10'
    }



    <不,我看到它可以用很多方式完成。这取决于关于构建的其他要求。


    I have the following gradle projects:

    jar-module-A
      +-- JavaEE lib(Dependency)
    
    war-module-A
      +-- jar-module-A
    

    I want to exclude JavaEE lib from WEB-INF/lib.

    1. Using providedCompile:

      Since jar-module-A is not a web module but jar, I cannot use providedCompile in build.gradle of jar-module-A.

    2. configurations { runtime.exclude JavaEE-lib }

      It excludes JavaEE from not only runtime but also testRuntime, It fails my unit tests in war-module-A by ClassNotFoundException.

    How can mitigate this situation?

    解决方案

    Brute force solution would be:

    apply plugin: 'java'
    apply plugin: 'war'
    apply plugin: 'maven'
    
    repositories {
      mavenCentral()
      maven {
        url "file:///tmp/repo"
      }
    }
    
    uploadArchives {
      repositories {
        mavenDeployer {
          repository(url: "file:///tmp/repo")
        }   
      }
    }
    
    dependencies {
      compile group: 'ruimo', name: 'module_a', version: '1.0-SNAPSHOT'
      testCompile group: 'junit', name: 'junit', version: '4.10'
    }
    
    war {
        classpath = classpath.filter {
            it.name != 'javaee-api-6.0.jar'
        }   
    }
    

    for module_b. It might be filename dependent (not sure of that). Maybe will have a look later on, but not sure - short with time.

    UPDATE

    More sophisticated:

    apply plugin: 'java'
    apply plugin: 'war'
    apply plugin: 'maven'
    
    repositories {
      mavenCentral()
      maven {
        url "file:///tmp/repo"
      }
    }
    
    uploadArchives {
      repositories {
        mavenDeployer {
          repository(url: "file:///tmp/repo")
        }
      }
    }
    
    dependencies {
      compile(group: 'ruimo', name: 'module_a', version: '1.0-SNAPSHOT') {
        transitive = false// here You can exclude particular dependency, not necessarily all
      }
      providedCompile group: 'javax', name: 'javaee-api', version: '6.0'
      testCompile group: 'junit', name: 'junit', version: '4.10'
    }
    

    No I see it can be done with many ways. It depends on what are other requirements regard build.

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

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