In the end I've used JarJar and created a modified JAR. Then I've added a dependency to my code and updated it manually so it now relates to the modified package instead of the original package.
Here's a procedure describing what I've done:
How to use JarJar in order to relocate classes of a JAR from one package to another
In this example we'll be changing the package from "com.fasterxml.jackson" to "io.kuku.dependencies.com.fasterxml.jackson".
- The source JAR is called "jackson-databind-2.6.4.jar" and new modified (target) JAR is called "kuku-jackson-databind-2.6.4.jar".
- The "jarjar" JAR file is in version 1.4
Create a "rules.txt" file. The contents of the file should be (watch the period before the '@' character):
rule com.fasterxml.jackson.** io.kuku.dependencies.com.fasterxml.jackson.@1
Run the following command:
java -jar jarjar-1.4.jar process rules.txt jackson-databind-2.6.4.jar kuku-jackson-databind-2.6.4.jar
Installing the modified JARs to the local repository
In this case I'm installing 3 files located on "c:my-jars" folder.
mvn install:install-file -Dfile=C:my-jarskuku-jackson-annotations-2.6.4.jar -DgroupId=io.kuku.dependencies -DartifactId=kuku-jackson-annotations -Dversion=2.6.4 -Dpackaging=jar
mvn install:install-file -Dfile=C:my-jarskuku-jackson-core-2.6.4.jar -DgroupId=io.kuku.dependencies -DartifactId=kuku-jackson-core -Dversion=2.6.4 -Dpackaging=jar
mvn install:install-file -Dfile=C:my-jarskuku-jackson-databind-2.6.4.jar -DgroupId=io.kuku.dependencies -DartifactId=kuku-jackson-annotations -Dversion=2.6.4 -Dpackaging=jar
Using the modified JARs in the project's pom
In this example, this is the "dependencies" element in the projects pom:
<dependencies>
<!-- ================================================== -->
<!-- kuku JARs -->
<!-- ================================================== -->
<dependency>
<groupId>io.kuku.dependencies</groupId>
<artifactId>kuku-jackson-annotations</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>io.kuku.dependencies</groupId>
<artifactId>kuku-jackson-core</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>io.kuku.dependencies</groupId>
<artifactId>kuku-jackson-databind</artifactId>
<version>2.6.4</version>
</dependency>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…