I need to add a dependency on jar (library/utility jar), it's bringing so many dependencies (these causing my app not to come up and things I have no control over as its caused by the third-party dependency conflicts) - but I just want to use one class from the imported jar. Say, for ex: if the class I am importing from the dependency jar has imports shown below code snippet, then I just want to bring the dependencies (like guava, java-dogstatsd-client etc) used by this class and exclude everything else.
I know I can use exclusions like How to exclude dependency in a Maven plugin? - but the shared library has so many dependencies - enumerating all of them doesn't seem to be reasonable.
And from Exclude all transitive dependencies of a single dependency - looks like I can exclude all transitive dependencies and specify explicitly the dependencies used by the class I am importing from the jar. Looks like this is the possible solution for my problem.
Is that the best possible solution?
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.timgroup.statsd.NoOpStatsDClient;
import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.StatsDClient;
import com.timgroup.statsd.StatsDClientException;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;