Create jar with special structure


(m. mueller) #1

Hello,
I am a gradle newbie…

I need to create a jar file with a special structure:

root
- classes
--- controllers
--- utils
- images
- js
-css
-META-INF
plugin.xml

I have an typical maven directory structure and define my source set this way:

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
        }
//        groovy {
//            srcDir 'src/main/groovy'
//        }
    }
}

My problem is, that the jarfile created does not have a “classes” directory which contains the ‘controllers’ and ‘utils’ classes.

Additionally, I have no idea how to put the css , images and js-files into the jar.
(The sources reside in /src/main/plugin/css , /src/main/plugin/js and /src/main/images )

I defined the jar task as follows:

// build a jar file
jar {
    manifest {
        attributes 'Built-By': 'me', 'Implementation-Title': 'VSX thrift plugin'
    }
    destinationDir = file("$rootDir/dist") // where to create the jar instead of /build/libs
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }

    from('src/main') {
        include '**/*.css'
        include '**/*.images'
        include '**/*.js'
    }

}

Can anyone please explain me how I can create the jar exactly with the structure I need?


(René Groeschke) #2

Hey.
first of all you would need to know how to distinguish controller or utils classes? are they stored in specific packages in your sourceSet? Also, it looks like you need a fat jar right?

the css / images / js stuff could be simplified by:

jar {
    ...
    from("src/main"){
        include "images/**"
        include "css/**"
        include "js/**"
    }
}

(m. mueller) #3

Thank you for answering. The jar will be uploaded to an existing webapp, which unpackes the whole and makes further steps, so that is the reason the jar file has not the usual structure. I do not know how to create the subdir classes within the jar and how to move my controller and util stuff into that classes subdir…


(m. mueller) #4

That’ my project structure…


(m. mueller) #5

this is what I have to create:


(m. mueller) #6

I tried the shadow Plugin from http://imperceptiblethoughts.com/shadow/#introduction
and configured

shadowJar {
    baseName = 'wio-ovsx-thrift-connection-gradle'
    classifier = null
    version = null
    relocate 'controllers', 'classes.controllers'
    relocate 'spaix', 'classes.spaix'
    relocate 'utils', 'classes.utils'
}

but

  1. It does not copy my css, js and images into the jar
  2. it leave an empty ‘classes’ directory behind

and most important: it changes the package name. So it does not work at all

List item