I have four build variants, A, B, C and D. For a specific activity I have common code in a base class in the main source sets. I want to additional functionality such that A & B have the same additionally functionality and C & D have the same functionality which is different from A & B. I have been able to do this by copy and pasting the extending class in the source sets for A & B and C & D respectively; however, that makes maintenance an issue. I cannot merge variants A & B or C & D because they do have other important differences. How do I include the class such that it is only in A and B references it and only C and D references it. I tried adding java source sets but then it couldn't find any other classes or other modules.
I was able to solve this issue by creating two new directories E & F. Then I added source sets for A & B to be their current source sets and E and for C & D I added F.
sourceSets {
A {
java.srcDirs = ['src/A/java', 'src/public/E']
}
B {
java.srcDirs = ['src/B/java', 'src/public/E']
}
C {
java.srcDirs = ['src/C/java', 'src/internal/F']
}
D {
java.srcDirs = ['src/D/java', 'src/internal/F']
}
}