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’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'
}
}
}