maven-shade-plugin
maven-shade-plugin copied to clipboard
[MSHADE-317] Source package name parse error
xuzhiyi opened MSHADE-317 and commented
If shadedPattern full contains pattern, package name gos wrong. Such as:
//代码占位符
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>com.alibaba.arthas.deps.org.objectweb.asm</shadedPattern>
</relocation>
</relocations>
!image-2019-04-13-17-58-43-081.png!
Affects: 3.2.1
Attachments:
- image-2019-04-13-17-58-43-081.png (99.72 kB)
- shade-issue-MSHADE-317.zip (22.04 kB)
Frantisek Hartman commented
I came across exactly the same issue.
This happens when
Module 1 shades a library & relocates it, e.g. com.google to org.example.com.google, the sources get relocated correctly.
<relocation>
<pattern>com.google</pattern> <shadedPattern>org.example.com.google</shadedPattern> </relocation>
Module 2 depends on Module 1, also uses the library & relocates it, you end up with overlapping resources which you can exclude somehow (set library in module 2 as provided, add it to exclusions, doesn't matter). The classfiles are correct, but the sources of Module1 get relocated again incorrectly:
E.g:
import org.example.com.google.common.collect.Lists.newArrayList;
The highlighted pattern is matched and replaced with shaded pattern ending up with the repetition of the shaded pattern prefix.
import org.example.org.example.com.google.common.collect.Lists.newArrayList;
See the project attached. [^shade-issue-MSHADE-317.zip]
I tracked down the problem to SimpleRelocator:
return sourceContent.replaceAll( " b" + pattern, shadedPattern );
The dot in the package is unfortunately a word boundary.
https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java#L219