Carleslc / Simple-YAML

This Java API provides an easy-to-use way to store data and provide configurations using the YAML format.
https://carleslc.me/Simple-YAML
GNU General Public License v3.0
132 stars 38 forks source link

java.lang.NoSuchMethodError: 'void org.yaml.snakeyaml.DumperOptions.setIndentWithIndicator(boolean)' #68

Closed thelipe7 closed 2 years ago

thelipe7 commented 2 years ago

I am getting the following error when creating a config: image

My code: image

Carleslc commented 2 years ago

This is not a Simple-YAML bug; it is a known issue related to a dependency clash between Velocity and Simple-YAML.

Velocity uses an older version of snakeyaml (1.26) than this library requires (1.30 or above, latest version uses 1.32). Because of this, there is a dependency clash, so even if the correct version is built with maven into your plugin through Simple-Yaml, in runtime at the moment of loading your plugin the first loaded version prevails, which sadly happens to be the older one loaded by the Velocity server.

See this comment to read a more detailed explanation for the error and the solution, which is relocation to differentiate both versions in runtime using different classpaths.

Example of maven-shade-plugin using relocation to solve the error:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.4.1</version>
  <executions>
    <execution>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <relocations>
          <relocation>
            <pattern>org.yaml.snakeyaml</pattern>
            <shadedPattern>net.servidor.commons.libs.snakeyaml</shadedPattern>
          </relocation>
        </relocations>
      </configuration>
    </execution>
  </executions>
</plugin>
Carleslc commented 2 years ago

Since 1.8.3 the manual relocation is not needed as it is already included. Add the relocation in 1.8.2 or update to 1.8.3. I'm closing the issue. Comment if you have any doubts.

thelipe7 commented 2 years ago

Thanks :)