Skip to content

Instantly share code, notes, and snippets.

@kylewm
Last active December 21, 2015 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylewm/6298171 to your computer and use it in GitHub Desktop.
Save kylewm/6298171 to your computer and use it in GitHub Desktop.
Gradle: question about dependency on an alternate configuration within a multi-project build

settings.gradle:

include 'core'
include 'plugin'

build.gradle:

project('core') {
  apply plugin: 'java'
  
  configurations {
    alternateCompile.extendsFrom compile
    alternateRuntime.extendsFrom runtime
    alternateArchives.extendsFrom alternateRuntime
  }

  sourceSets {
    alternate {
      java {
        srcDir 'src/alt/java'
      }
      compileClasspath += main.output
    }
  }
  
  task alternateJar(type: Jar) {
    classifier 'alternate'
    from sourceSets.alternate.output
  }

  artifacts {
    alternateArchives alternateJar
  }
}

project('plugin') {
  apply plugin: 'java'

  dependencies {
    compile project(path: ':core', configuration: 'alternateArchives')
  }

  task listJars << {
    configurations.compile.each { 
      println it.name
    }
  }
}

console output

> gradle -q :plugin:listJars
core.jar
core-alternate.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment