0

this is my first time working with Java and Maven, these are some of my dependencies on pom.xml

...

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.10</version>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.24</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

After a couple of hours strugling with a NoClassDefFoundError com/google/gson/Gson I solved it (thanks to NoClassDefFoundError on Maven dependency) by adding

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.4</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>

But the question is

  • Why dependencies as Gson need the shading plugin to make an uber jar while others like Lombok/Guice/Junit does not? (I was working with no problem at all until I added Gson)

Thanks

ca-hercor
  • 1
  • 1

0 Answers0