Cannot exclude a depedency inside a jar


(Guy Grinwald) #1

Hello, I have a project (B) which compile a local jar (A). I need to exclude a dependency inside the jar (A) but I can’t do it when building the jar. I can build the jar how ever I want but I have to have those dependencies in it and only exclude them in project B.

This is build.gradle the jar of project A:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'

repositories {
    mavenCentral()
}

jar {
    baseName = 'test'
    version =  '0.1.0'

    manifest {
        attributes ("Main-Class": "Main")
    }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE") // I need this excluded later
    compile("org.springframework.boot:spring-boot-starter-jetty:1.4.0.RELEASE") // I need this excluded later
    /*
    some other dependencies here
    */
}

This is build.gradle for project B:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'

repositories {
    mavenCentral()
    flatDir(dirs: "lib")
}

sourceCompatibility = 1.8

dependencies {
   compile ':test:0.1.0' // this is the jar I need to exclude some things from

   compile("org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE")
   compile("org.springframework.boot:spring-boot-starter-jetty:1.4.0.RELEASE")
}

It seems like using a regular exclude clause does not work

compile (':test:0.1.0') {
    exclude group: 'org.springframework.boot' // doesn't work
}

Any help would be very appericiated


(Stefan Oehme) #2

An exclusion based on the group won’t work with a flatDir repo, as a flat dir has no group information. You’ll need to use a Maven or Ivy repository instead.


(Guy Grinwald) #3

Thank you. I’ll find a way to work around that