How to define same sources in two different build.gradle files?


(Ganesh) #1

I have two build.gradle files at different levels in the file hierarchy as shown in the diagram below:

application
|_component1
|__build.gradle
|__component1_1.c
|__component1_1.h
|__component1_2.c
|__tests
|___build.gradle
|___component1_test.c
|___component1_test.h

I would like to include the source files (component1_1.c and component1_2.c) in both these build.gradle files but would like to define them only once. How can I get this to work?

In the build.gradle under component1, I have defined the sources using project.ext.SRC.

project.ext.SRC=["component1_1.c", "component1_2.c"]

But I am not sure how I can include it under tests/build.gradle

I did something like this in the build.gradle under tests

project.ext.SRC=["component1_test.c"] SRC += project(':application/component1').SRC

However, this means I am somehow coupling two sub-projects and I don’t want to do that. Statements such as this would be affected depending on the order in which gradle configures the subprojects. What would be a clean solution to this requirement?