Is it possible to place class files under a specific folder in a jar

(manuel.meiners) #1

I am creating a jar file with the jar task. Is it possible to define a subdirectory where the class files will be placed. For example, the class com.example.MyClass shouldn’t be placed in the root (com/example/MyClass.class) of the jar but in the defined subdirectory (my-subdirectory/com/example/MyClass.class). Is this possible?

I played around with “into” (,%20groovy.lang.Closure)) but i don’t get it work.


(Alexander Haskell) #2

I’ve had trouble with this too. The ‘from’ and ‘into’ methods don’t act the way you might expect them to. It seems that they are not meant for redirecting, but for when you’re including files that may be outside of your ${buildDir}/classes directory.

But what you can do use the method ‘eachFile’.

jar {
    eachFile {
        if (it.path.endsWith('/MyClass.class') {
            into 'my-subdirectory/com/example'

You could modify the ‘if’ to fit your needs.

(Luke Daley) #3

@mm: does the above solve your problem?