Gradle: How to make a compile scope file dependency excluded in packaging?

I have a multi-module gradle project with the following basic structure:

root
  core
  c-interface
  m-interface

The c-interface and m-interface both depend on the core project:

compile project(':root:core')

c-interface and m-interface use the WAR plugin, but core does not and is just a jar.

In the core project, I am pulling in some file system dependencies with the following. One of these dependencies I cannot have packaged in the WARs generated by c-interface and m-interface. Previously I had this dependency in a nexus maven repository so I could exclude it by group,name,version in a providedRuntime configuration in c-interface and m-interface.

I cannot figure out how to do the same for the file dependency. The gradle dependencies task does not list file dependencies so I don't know what I would put in a providedRuntime.

I read http://issues.gradle.org/browse/GRADLE-471 but trying to use the idea there doesn't seem to remove the archive from my packages. Here is what I am currently defining (in core's build.gradle):

compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compile(files('dependencies/compile/archive/management.jar')){ notPackaged = true  } // Excludes it from all publications

Update

providedCompile without war plugin looked like a possibility. I set this up in the core build.gradle and it compiled fine, but c-interface and m-interface also needed the dependency at compile time. Including the file as providedCompile (or even a sanity check with compile) in c-interface and m-interface did not fix compile time errors related to missing the management.jar dependency. My speculation is because it was already scoped as providedCompile in core that the new declarations are ignored in c-interface and m-interface.

core/build.gradle:

configurations { providedCompile }

dependencies {
    providedCompile files('dependencies/compile/archive/management.jar')
}

sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile

c-interface/build.gradle:

providedCompile files('dependencies/compile/archive/management.jar')

Answers


There probably is a cleaner and simpler solution but you could then specify a custom configuration:

configurations {
    compileOnly
}

and then specify all dependencies:

dependencies {
    compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
    compileOnly files('dependencies/compile/archive/management.jar')
}

Finally add the compileOnly configuration to classpaths of all source sets

sourceSets.all {
    compileClasspath += configurations.compileOnly
}

This way management.jar should be on the classpath for compilation but won't be packaged.

EDIT Only now I fully understand your problem. The following worked for me on a test project.

In core project gradle file:

repositories {
    flatDir {
        dirs 'dependencies/compile/archive'
    }
}

dependencies {
    compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
    compile ':management:'
}

In project that depends on core:

repositories {
    flatDir {
        dirs new File(project(':core').projectDir, 'dependencies/compile/archive')
    }
}

dependencies {
    compile(project(':core')) {
        exclude module: 'management'
    }
    compileOnly ':management':
}

sourceSets.all {
    compileClasspath += configurations.compileOnly
}

Need Your Help

Portable way to “unpoint” a pointer typedef?

c typedef typeof

This is unfortunately defined in some external library: cannot touch!

Google like search string parsing to sql

postgresql solr lucene indexing full-text-search

Lets say I have a web application with a postgres database. I would like to add a google like search string(abc + site:xyz + size>800 -pqrs) to it. So this string would generate a sql used to return

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.