We are moving from Maven to Gradle and I am stuck on the issue below. In our current pom.xml we have this:
<resources>
<resource>
<targetPath>deploy/config/directory1</targetPath>
<directory>config/directory1</directory>
</resource>
<resource>
<targetPath>deploy/config/directory2</targetPath>
<directory>config/directory2</directory>
</resource>
<resource>
<targetPath>deploy/scripts</targetPath>
<directory>scripts</directory>
</resource>
We have a unit test that does
getClass().getResource("/deploy/config/directory1/somefile.txt")
I do not want to change the pom.xml as that structure is needed for deployment reasons until we fully migrate to Gradle. I am trying to do the equivalent in gradle with not much success:
sourceSets {
main {
java {
srcDirs 'src'
}
resources {
srcDirs = [
"config/directory1",
"config/directory2",
"scripts",
]
// output.resourcesDir = "$buildDir/deploy"
}
}
A have a few issues with this:
- The files in the config/directory1 and config/directory2 are copied to the root location of the resources folder. I would like to keep the structure the same so there would be a single config directory under the resources dir and then config dir would have directory1 and directory2.
- I can set the output.resourcesDir as shown however that means I have to change my java code to
getClass().getResource("somefile.txt")
which is what I have to avoid.
Thankyou