How disable merging with dependencies during java build?

I have java project with some packages:

org.test.pack1 org.test.pack2 org.test.pack3 org.test.pack4

Later i decided to include pack2 and pack4 as external libraries


org.test.pack1 org.test.pack3

Example of gradle script

apply plugin: 'java'
  dependencies {
            [group: 'org.test', name: 'pack2', version: '1.0.0'],
            [group: 'org.test', name: 'pack4', version: '1.0.0'],

After successful build in result JAR file I found classes from pack2 and pack4 (not all but only really used by classes in pack1).

And my simple question sounds like: Why? and second: how to disable this ?

My real use case - j2ee project, where random classes may cause unexpected and strange errors.