maven-shade-plugin icon indicating copy to clipboard operation
maven-shade-plugin copied to clipboard

[MSHADE-317] Source package name parse error

Open jira-importer opened this issue 6 years ago • 2 comments

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:

jira-importer avatar Apr 13 '19 10:04 jira-importer

Karl Heinz Marbaise commented

Can you please make an example project and attach it to this ticket?

jira-importer avatar May 15 '19 20:05 jira-importer

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

jira-importer avatar Jan 08 '21 08:01 jira-importer