class override (same full class name)

Jackie
Dec 28, 2021

following up with https://lwpro2.dev/2021/12/28/maven-nested-modules/ and https://lwpro2.dev/2021/12/14/microservies-in-monorepo/, there are times where a class defined upstream (either third party or shared library internally) should be overriden.

The trick is to keep the class name exact with the same package name. when maven shaded the class, it would pick up the class from the closest level.

For example, if module ACore has a class names org.wordpress.util.DomainMapper, a class with the exact same name org.wordpress.util.DomainMapper could be created in A1 module to override the provided functionality.

when build module A with -amd, it would generated a A2 jar, which contains the compiled class binary from ACore. while the generated A1 jar, would contain the override class created in A1 module.

Published

Originally published at https://lwpro2.dev on December 28, 2021.

--

--