I'm working in a multi-module Gradle application where Project B will depend on Project A, and are imported as dependencies as such:
compile project(":modules:lib-module")
Project A, let's call lib-module
, in this case contains XML files for configuring Log4J2 that are typically used unmodified by the dependant projects. In this one case, however, I need to completely overwrite those files from those that are in lib-module
.
I know that I can write code to handle this within the bootstrapping of the module where Log4J2 gets set up, however I'm looking to see if there is a way that I can overwrite these files at build time using Gradle without having to add additional code to the application itself.
Since this particular module is used as an AWS Lambda function we use a special build script:
task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtime
}
}
build.dependsOn buildZip
I was hoping I could update the from processResources
subtask to copy this module's resource files to the location of the dependency's resource files, but that didn't work as I expected.
I explored the contents of the jars within the "lib" folder and they contain the original XML files, most likely because that module has its own build.gradle
file.
Is there a way to actually completely overwrite a dependent project's resource files in the parent project's build.gradle
file?
NOTE: I purposely did not tag AWS-Lambda or Log4J2 since it's irrelevant to this question, but wanted to provide context to the reader. This question is ONLY how to solve this issue with Gradle.