4

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')
Community
  • 1
  • 1
Rich
  • 2,805
  • 8
  • 42
  • 53

1 Answers1

13

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
}
cmcginty
  • 113,384
  • 42
  • 163
  • 163
erdi
  • 6,944
  • 18
  • 28
  • This looks pretty similar to the providedCompile configuration I have in my question. Produces the same results for me, management.jar does not resolve on compile of c-interface and m-interface – Rich Apr 19 '13 at 19:30
  • Yeah, looks like I completely skipped that section of your question... could you print all the files on compile classpath for main source set in an afterEvaluate block? – erdi Apr 19 '13 at 20:09
  • something like: afterEvaluate { sourceSets.main.compileClasspath.files.each { println it } } – erdi Apr 19 '13 at 20:14
  • Sure. Running the afterEvaluate in both core and c-interface I can tell you that management.jar is listed for core's afterEvaluate block but not for c-interface's afterEvaluate block. – Rich Apr 19 '13 at 20:34
  • If I add the same compileOnly/providedCompile configuration to the c-interface's build.gradle, management.jar does appear in the list but the compileJava task still fails not being able to resolve the packages. – Rich Apr 19 '13 at 20:55
  • Could not find property 'compileClassPath' on source set 'main' – cmcginty Sep 24 '13 at 02:45