Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
885 views
in Technique[技术] by (71.8m points)

gradle - How to exclude specific jars from WEB-INF/lib

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...