How to exclude specific jars from WEB-INF/lib

后端 未结 2 1370
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 04:05

I have the following gradle projects:

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

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

I want to exclude JavaEE l

相关标签:
2条回答
  • 2020-12-22 04:30

    If the transitive is not working, can try resolution startegy. I was fed up with the transitive or even normal exclude.

    https://docs.gradle.org/2.2.1/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

    dependencies{
            compile(group: 'ruimo', name: 'module_a', version: '1.0-SNAPSHOT')
        }
    
    configurations.all {
        resolutionStrategy {
            force ruimo:module_a:1.0-SNAPSHOT
        }
    }
    
    0 讨论(0)
  • 2020-12-22 04:40

    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.

    0 讨论(0)
提交回复
热议问题