Skip to content

Instantly share code, notes, and snippets.

@ghale
Last active June 18, 2020 17:14
Show Gist options
  • Save ghale/e5ab42ea8d0914aaadea9669dfa22c20 to your computer and use it in GitHub Desktop.
Save ghale/e5ab42ea8d0914aaadea9669dfa22c20 to your computer and use it in GitHub Desktop.
Variant aware dependency management
// Declare a new attribute type to use for selection
def usageAttribute = Attribute.of("com.adyen.usage", String)
// In both the producer and consumer, register the new attribute and set
// up a configuration associated to the attribute
subprojects {
dependencies.attributesSchema {
attribute(usageAttribute)
}
configurations {
web {
attributes {
attribute(usageAttribute, "web-resource")
}
}
}
}
project(':web-resources') {
apply plugin: 'java'
task webZip(type: Zip) {
from 'resources'
classifier 'web'
}
// Associate an artifact with the configuration
artifacts {
web webZip
}
}
project(':war') {
apply plugin: 'java'
dependencies {
// declare a dependency on the project in the configuration with the
// appropriate attribute
web project(':web-resources')
}
task copyWeb(type: Copy) {
from configurations.web
into layout.buildDir.dir('resources')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment