Add resources, config files to your jar using gradle

91

How do I add config files or any other resources into my jar using gradle?

My project structure:

src/main/java/com/perseus/.. --- Java packages (source files)

src/main/java/config/*.xml --- Spring config files

Expected jar structure:

com/perseus/.. --- Java packages (class files)

config/*.xml --- Spring config files

This question is tagged with gradle build.gradle

~ Asked on 2014-07-13 15:39:45

The Best Answer is


84

I came across this post searching how to add an extra directory for resources. I found a solution that may be useful to someone. Here is my final configuration to get that:

sourceSets {
    main {
        resources {
            srcDirs "src/main/resources", "src/main/configs"
        }
    }
}

~ Answered on 2016-08-16 18:26:23


71

Move the config files from src/main/java to src/main/resources.

~ Answered on 2014-07-13 20:55:24


Most Viewed Questions: