How to exclude file dependency in compile configuration from the runtime configuration


(Scott Stewart) #1

Not sure how many different scenarios this is useful, so I’ll be specific:

I’m trying to build a module with a dependency on weblogic.jar. Since weblogic.jar uses the classpath in its manifest to include other jars (which also use their classpaths to bring in even more jars) using relative path locations, it’s hard to avoid including weblogic.jar in the classpath in it’s original location. So I include it like:

compile files(webLogicHome + '/server/lib/weblogic.jar');

However, the target systems where the module is deployed already have weblogic installed, so we don’t want to include the 36 MB jar in the distribution archive. And… the distribution archive is created using the runtime classpath:

task tar(type: Tar) {
        from configurations.runtime
        from configurations.runtime.allArtifacts.files
    }

Finally to the question: What is the best way to exclude this file-dependency from the runtime classpath? I tried several variations on this but none worked:

configurations {
    runtime.exclude( files(webLogicHome + '/server/lib/weblogic.jar') )
}

Thanks!


(René Groeschke) #2

Hello Scott, to get this working you should use an additional configuration. Have a look at the following snippet that shows the usage of a providedCompile configuration, that is used for compilation, but excluded in the tar task:

configurations{
 providedCompile
 compile.extendsFrom providedCompile
}
  dependencies{
 providedCompile files('server/lib/weblogic.jar');
 }
  task tar(type: Tar) {
        from configurations.runtime - configurations.providedCompile
        from configurations.runtime.allArtifacts.files
}

regards, René


(Scott Stewart) #3

Hi Rene,

Thanks for your answer, and it’s very close, but the way I see it weblogic.jar should never be included in the runtime configuration as this module will always be deployed in a weblogic environment. This module is depended on by other modules (many other modules), so it seems that each would have to exclude weblogic.jar when declaring the dependency… I didn’t know you could use the subtraction operator, that’s cool. I keep trying variations on the following, but no luck yet:

configurations {
    providedCompile
    compile.extendsFrom providedCompile
    runtime = runtime - providedCompile
}

or

dependencies {
    compile...
    providedCompile files(webLogicHome + '/server/lib/weblogic.jar');
    configurations.runtime = configurations.runtime - configurations.providedCompile
}

Hopefully I’ll post something that works soon…


(Scott Stewart) #4

So, couldn’t find a way to exclude a file dependency in the compile configuration from the runtime config. However, the module: exclude works fine, so instead of including weblogic as a file, we just configured a flat-directory repository to the weblogic lib directory and refer to the dependency as ‘:weblogic@jar’:

repositories {
    flatDir(dirs: file(webLogicHome + '/server/lib'))
}
  configurations {
    compile { transitive = false }
    runtime.exclude module:'weblogic'
}
  dependencies {
    compile ':weblogic@jar'
}