How to overwrite classes in an existing jar?


(Carlo Luib-Finetti) #1

I have some curious project inheritance, where we use a Jar from some other project, but where we do overwrite some classes with the same name and package path as those in the jar. So the build task should be: - compile sources - jar sources into existing jar.

I have tried with overriding task jar like this:

task jar(type: Jar, overwrite: true) {
 from zipTree(lib_xxx.xxx_bof_dep90)
   from sourceSets.main.output.classesDir
 }

This works as the jar task puts the compiled classes into the existing jar - but it leaves existing classes in that jar. So in effect, in the new jar I have duplicate classes.

How can I tell Gradle to overwrite existing classes with the ones just compiled?


(Peter Niederwieser) #2

Overwriting archive files isn’t currently supported. You either have to go through a temporary directory, or use the Ant Jar task.


(Carlo Luib-Finetti) #3

“go through a temporary directory”’?

Do I have to - inflate the existing jar into that temporary dir,

  • copy the build classes into that dir, overwritting existing classes and

  • then do the jar task with “from” argument of that temporary directory?


(Peter Niederwieser) #4

Yes. Or you patch the Jar with Ant’s Jar task.


(Carlo Luib-Finetti) #5

ok, thanks for your support!