Shaded class (from uber jar) are not visible in other project to import

417 views Asked by At

I am trying to shade dependency (building uber jar) and importing in other project.In uber jar I can see class but when I try to import the shaded folder/package do not show.Below are my pom.xmls

Test1 with shaded dependency and uber jar

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>


  <properties>
        <jdk.version>1.8</jdk.version>
        <jodatime.version>2.5</jodatime.version>
    </properties>

  <dependencies>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${jodatime.version}</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>test</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                </configuration>
            </plugin>

            <!-- Set a compiler level -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>

        <!-- Maven Shade Plugin -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>3.1.0</version>
          <executions>
             <!-- Run shade goal on package phase -->
            <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
              <relocations>
                <relocation>
                    <pattern>org.joda</pattern>
                    <shadedPattern>test.shaded.org.joda</shadedPattern>
                </relocation>
                </relocations>

            </configuration>
              </execution>
          </executions>
        </plugin>

        </plugins>
    </build>


</project>

Test2 where I added test1 as dependency

    <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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>test2</groupId>
      <artifactId>test2</artifactId>
      <version>0.0.1-SNAPSHOT</version>

        <dependencies>
            <dependency>
                <groupId>test</groupId>
                <artifactId>test</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </project>

But when I try to import test.shaded.org.joda in Test2 project, dependency is not showing.

0

There are 0 answers