Can gradle keep all source sets in an additional subdirectory?


(rainer.frey) #1

I’m trying to move an existing Java project to gradle. It follows the usual source set conventions for main, test and two additional source sets, except that all source directories are in an additional subdirectory within the project. To visualize, it looks like

client

± src

± main

|

± java

|

± resources

± test

|

± java

|

± resources

Is there a way to specify a base directory for all source sets, including the implicit ones, without reconfiguring the srcdir for each source set individually?

Thanks Rainer


(Peter Niederwieser) #2

There is no such thing as a base directory for all source sets. You can, however, loop over all source sets and set the source dirs in a generic fashion. Something like:

sourceSets.all {
  java.srcDirs = ["client/src/$name/java"]
  resources.srcDirs = ["client/src/$name/resources"]
}

(rainer.frey) #3

Ah thanks - I didn’t think of using the name dynamically in a configuration loop.