How can I manually rearrange the directory structure of the jar that gradle produces for me, and then place images in an arbitrary folder?


(willbdaniels) #1

So, I have a potentially tricky problem (with a probably easy solution!)

Alright, what the problem is, is i’m making a javafx application and attempting to build and compile it under gradle. Ok, seems easy enough, there’s even a wonderful plugin for it out there ( https://bintray.com/shemnon/javafx-gradle/gradle-javafx-plugin/0.3.0 ). The problem is, the way the javafx project is setup, the directory structure looks something like this >

Project -----

|

|–Package ‘Mark’

|

|

Package Mark.styles (which contains a lot of things like .png’s etc.etc.)

Now there’s more to the project, but those are the two pieces that i’m concerned with. If you can imagine, these two folders are nested, one with java classes on the top level, and then a sub-folder that is holding all of the resources. Ok, great, no big deal.

the ‘big deal’ comes from the fact that when I use gradle to package up my jar as such:

sourceSets {
  main {
    resources.srcDirs = ["src/main/resources"]
  }
}
configurations {
 bundle
    compile.extendsFrom bundle
}
  jar {
 baseName = "IFRCalculator"
 from configurations.bundle.collect { it.isDirectory() ? it : zipTree(it)}
 manifest {
  attributes("Main-Class": "Mark.mark");
 }
}

If you can imagine, it makes a folder in my jar called “Mark” (fine, no big deal), and it makes a folder at the SAME LEVEL called “styles”. well ugh. I need styles to be inside the mark folder, I feel like I’m one line of code away from solving this extremely frustrating problem that has no clear googled answer. (Or I was too naive to see it fit into my context)

any help would be greatly appreciated! :smiley:


(willbdaniels) #2

So, I actually just solved this. It turns out that the magic to make it work, is to make a directory structure that you want, and then to essentially fill it with all of your resources you need, and manually override the default like so: (assuming the directory you setup for this is called $buildDir)

sourceSets {
  main {
    output.resourcesDir = '$buildDir/'
  }
}

Kind of (a lot) of a hack, and if anyone knows a better way to pull it in from src/main/resources and get the structure I want, I’m all ears.

-Will