Gradle multi-project build - where to put global resources?

Viewed 802

I have Gradle multi-project solution looking as the following:

---Root
-----SubProject1
-----SubProject2
-----SubProject3

In order to avoid duplication, I want to use same log4j2 logger configuration file ("log4j2.xml") for all sub-projects.

is it possible to put it somewhere so it will affect all sub-projects? I prefer solution transparent to each sub-project.

For example, in .NET solution I was able to put log4net configuration into main app.config, and it was applied to all projects in solution. I want to achieve something similar in Java...

1 Answers

You can configure your subprojects from the root project build.gradle script, using the subprojects block (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:subprojects(groovy.lang.Closure) )

For example, you can configure the sourceSets, in order to append some "shared resources" directory to the subproject's sourceSets.main.resources property, as follows:

root project's build.gradle

subprojects {
    apply plugin: 'java'
    main {
        resources {
            srcDirs += "../shared-resources"
        }
    }
}

In your root project you can create a shared-resources that will contain all shared configuration files, like log4j.xml

Related