Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add resources, config files to your jar using gradle

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

like image 548
Pritesh Mhatre Avatar asked Jul 13 '14 15:07

Pritesh Mhatre


People also ask

How do I create a gradle config file?

In Eclipse, select File > Export. In the window that appears, open Android and select Generate Gradle build files. Select the project you want to export for Android Studio and click Finish.

How do I add plugins to build gradle?

While creating a custom plugin, you need to write an implementation of plugin. Gradle instantiates the plugin and calls the plugin instance using Plugin. apply() method. The following example contains a greeting plugin, which adds a hello task to the project.


2 Answers

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"         }     } } 
like image 190
Wellington Souza Avatar answered Oct 19 '22 17:10

Wellington Souza


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

like image 32
Peter Niederwieser Avatar answered Oct 19 '22 18:10

Peter Niederwieser