Reputation: 11377
With maven pom having this in build configuration we are building a jar file which has resource files right in packages near class files (this is in my case necessary as some class files rely on convention over configuration and expect those resource files to be right next to them).
<build>
...
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
<include>**/*.css</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.css</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
...
</build>
How can we do the same with gradle?
Upvotes: 3
Views: 9088
Reputation: 84854
You need to add the following piece of code:
apply plugin: 'java'
jar {
from('src/main/java') {
include '**/*.properties'
include '**/*.xml'
include '**/*.css'
}
}
It works in the following way:
➜ 33416293 git:(master) ✗ tree
.
├── build.gradle
└── src
└── main
└── java
└── lol
├── Lol.java
├── lol.css
├── lol.properties
└── lol.xml
4 directories, 5 files
➜ 33416293 git:(master) ✗ gradle jar
:compileJava
:processResources UP-TO-DATE
:classes
:jar
BUILD SUCCESSFUL
Total time: 3.035 secs
➜ 33416293 git:(master) ✗ jar -tvf build/libs/33416293.jar
0 Thu Oct 29 15:55:40 CET 2015 META-INF/
25 Thu Oct 29 15:55:40 CET 2015 META-INF/MANIFEST.MF
0 Thu Oct 29 15:55:40 CET 2015 lol/
242 Thu Oct 29 15:55:40 CET 2015 lol/Lol.class
8 Thu Oct 29 15:51:28 CET 2015 lol/lol.css
9 Thu Oct 29 15:47:00 CET 2015 lol/lol.properties
15 Thu Oct 29 15:51:22 CET 2015 lol/lol.xml
➜ 33416293 git:(master) ✗
Here you can find demo.
Upvotes: 6