title: How to relocate, re-install, and re-publish every packages in a dependency jar using maven plugins?
body: <p>Here is a real case I have encountered on an apache project:</p>
  
  <p>Project <code>spark</code> has a diamond dependency:</p>
  
  <pre><code>spark -&gt; hive v1.2.1
  spark -&gt; avro -&gt; hive v2.3.0
  </code></pre>
  
  <p>hive v1.2.1 &amp; v2.3.0 use the same package names (org.apache.hive), which causes jar hell.</p>
  
  <p>Due to this concern, I want to relocate everything (both packages &amp; classes) in hive v1.2.1 to another path (spark-project.org.apache.hive), bundle the relocated things into a new jar, re-install the new jar into local .m2 repository, and (optional) re-publish the new jar into remote maven central channel.</p>
  
  <p>So far, I've found none of the maven plugin capable of doing this: The maven shade plugin can do the relocation, however:</p>
  
  <ol>
  <li>it won't re-install &amp; re-publish the new jar</li>
  <li>the new jar contains all packages in my own project, not only packages in a dependency</li>
  <li>as a result of 2, if multiple dependencies all contain the package <code>org.apache.spark</code>, then everything inside the package in all the dependencies will be relocated, while in reality only 1 of them should be relocated.</li>
  </ol>
  
  <p>So I'm wondering if there is a better option. Due to the flexible deployment requirement of this project I'm not allowed to use any customised classloaders, including those invented by OSGi</p>