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

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” (http://gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:into(java.lang.Object,%20groovy.lang.Closure)) but i don’t get it work.

Thanks

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.

@mm: does the above solve your problem?