Gradle sourceSet merge with overlapping files

58 Views Asked by At

I'm trying to merge or extend a 'main' resources with a second sourceSet's resources.

build.gradle snippet:
sourceSets {
  main { 
    resources { //contains main-specific foo.properties, among other common files }
  }
  appVariant {
    resources {
      // 'src/appVariant/resources/foo.properties' exists with different content from main's

      // Works as a merge, but main's file overwrites the variant's
      // And I don't see a way to apply a DuplicatesStrategy in this context
      source(sourceSets.main.resources)

      // Same as above, almost as if the exclude is ignored.
      source(sourceSets.main.resources).exclude('foo.properties')

      // The exclude works here, but modifies the main sourceSet's FileTree too
      source(sourceSets.main.resources.exclude('foo.properties'))
    }
  }
}

This is for a project using java & application plugins. Is it possible I'm approaching this from the wrong angle? I'd like to ultimately build a second distribution using the appVariant sourceSet, and runAppVariant task as well.

I suppose it'd be possible to create sourceSets.common.resources, and share between the two? But that seems like a verbose approach for what seems like a relatively simple problem, unless there were several more variants.

I know there's brute-force options for modifying the ./build/ dir contents, or using copy tasks. But I'm trying to learn better approaches using Gradle's existing design structure.

0

There are 0 best solutions below