[ 
https://issues.apache.org/jira/browse/MSHADE-345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17693720#comment-17693720
 ] 

Javier Neira Sanchez edited comment on MSHADE-345 at 2/26/23 10:16 PM:
-----------------------------------------------------------------------

[~icshuo] hey, thanks for the hint to try to reroduce the issue. I followed it, 
you can check that version at 
[https://github.com/jneira/maven-shade-plugin/tree/SHADE-345_scala-package-relocation/src/it/projects/MSHADE-345_scala-package-relocation/src/main/scala]

The scala app looks like:
{code:java}
import org.apache.logging.log4j.scala.Logger;
import org.apache.logging.log4j.scala.Logging;
object MyApp extends App with Logging {  
  println("Logger FQCN: " + Logger.FQCN)
  logger.info("Test Logging")
} 
{code}
Executing the app shows
 
{code:java}
Logger FQCN: relocated.scala.Logger${code}
 
Which still seems to be correct
And, well, the bytecode generated for relocated classes also looks good, for 
example:
 
{code:java}
public void delayedInit(relocated.scala.Function0<relocate
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #65                 // Method reloca0;)V
       5: return{code}

 
 


was (Author: jneira):
[~icshuo] hey, thanks for the hint to try to reroduce the issue. I followed it, 
you can check that version at 
[https://github.com/jneira/maven-shade-plugin/tree/SHADE-345_scala-package-relocation/src/it/projects/MSHADE-345_scala-package-relocation/src/main/scala]

The scala app looks like:

```
import org.apache.logging.log4j.scala.Logger;
import org.apache.logging.log4j.scala.Logging;

object MyApp extends App with Logging {
  println("Logger FQCN: " + Logger.FQCN)
  logger.info("Test Logging")
}
```
 
Executing the app shows
 
```
Logger FQCN: relocated.scala.Logger$
```
 
Which still seems to be correct
And, well, the bytecode generated for relocated classes also looks good, for 
example:
 
```
public void delayedInit(relocated.scala.Function0<relocate
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #65                 // Method reloca0;)V
       5: return
```
 
 

> Package relocation appears not to work with Scala
> -------------------------------------------------
>
>                 Key: MSHADE-345
>                 URL: https://issues.apache.org/jira/browse/MSHADE-345
>             Project: Maven Shade Plugin
>          Issue Type: Bug
>            Reporter: Graham Pople
>            Priority: Major
>         Attachments: image (4).png
>
>
> (Apologies if this is a known issue, I searched but couldn't find it.)
> I have a small pom.xml that's simply pulling in two dependent libraries from 
> Maven, and shading them:
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <project xmlns="http://maven.apache.org/POM/4.0.0";
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
> http://maven.apache.org/maven-v4_0_0.xsd";>
>     <modelVersion>4.0.0</modelVersion>
>     <groupId>com.couchbase.client</groupId>
>     <artifactId>scala-deps</artifactId>
>     <version>1.1.1-SNAPSHOT</version>
>     <packaging>jar</packaging>
>     <name>Couchbase Scala Dependencies</name>
>     <description>Shadowing dependencies for Scala prokect</description>
>     <dependencies>
>         <dependency>
>             <groupId>com.github.plokhotnyuk.jsoniter-scala</groupId>
>             <artifactId>jsoniter-scala-core_2.12</artifactId>
>             <version>1.0.0</version>
>         </dependency>
>         <dependency>
>             <groupId>com.github.plokhotnyuk.jsoniter-scala</groupId>
>             <artifactId>jsoniter-scala-macros_2.12</artifactId>
>             <version>1.0.0</version>
>         </dependency>
>     </dependencies>
>     <build>
>         <plugins>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-shade-plugin</artifactId>
>                 <version>3.2.1</version>
>                 <configuration>
>                     <relocations>
>                         <relocation>
>                             <pattern>com.github.plokhotnyuk</pattern>
>                             
> <shadedPattern>com.couchbase.client.scala.deps.plokhotnyuk</shadedPattern>
>                         </relocation>
>                     </relocations>
>                     <createSourcesJar>true</createSourcesJar>
>                     <shadeSourcesContent>true</shadeSourcesContent>
>                     <shadedArtifactAttached>true</shadedArtifactAttached>
>                 </configuration>
>                 <executions>
>                     <execution>
>                         <phase>package</phase>
>                         <goals>
>                             <goal>shade</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>             </plugin>
>         </plugins>
>     </build>
> </project> {code}
> From this I expect to get an uber-jar containing those dependencies, with 
> classfiles inside 
> com/couchbase/client/scala/deps/plokhotnyuk/jsoniter_scala/..., and with 
> those files starting "package com.couchbase.client.scala.deps.plokhotnyuk...".
> However, while the files are moved to the correct file structure, the package 
> names aren't adjusted.  Here's a screenshot from the sources jar:
> !image (4).png!
>  
> And my experiments with the binary jar itself seem to indicate that the same 
> issue exists at the bytecode level in the regular jar too, e.g. the 
> classfiles are in the right place but the package hasn't been changed.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to