CompileOnly a lib, but it is still built in apk

I have compileOnly Jackson in the build.gradle with something like this:

dependencies {

CompileOnly ‘Jackson’

}

However, I can still find Jackson lib in classes.dex when analyzing apk and it caused duplicated class issue (I have another apk providing Jackson class and used at run time)

Some observations:

  1. I’ve tried to remove implementations that has dependencies with Jackson, but Jackson is still imported in apk.
  2. only classes that are directly called by apk package are imported in classes.dex (not the whole Jackson lib)
  3. I cannot exclude Jackson because it will cause build fail.

Is it possible that classes are directly called by the apk package are included in apk, even if I used compileOnly?