tchristofferson
tchristofferson

Reputation: 303

Maven compiler plugin Unsupported class file major version 60

I am updating a Spigot (Minecraft) plugin and the newest version of Spigot requires Java 16. In my pom I changed the maven compiler plugin target to 16 and the source is still 1.8. Now I am getting the following errors:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade (default) on project Plugin: Error creating shaded jar: Problem shading JAR C:\Users\Trent\workspace\Stocks\Plugin\target\Plugin-1.0-SNAPSHOT.jar entry com/tchristofferson/stocks/commands/StockbrokerCommand.class: java.lang.IllegalArgumentException: Unsupported class file major version 60

pom:

<?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/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.tchristofferson</groupId>
  <artifactId>Stocks</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>

  <modules>
    <module>API</module>
    <module>Plugin</module>
  </modules>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>16</target>
          <release>16</release>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
  </distributionManagement>

</project>

Upvotes: 3

Views: 26237

Answers (5)

Noniq
Noniq

Reputation: 399

To elaborate on the answer @tchristofferson has given, I got it working with Java 16 by setting snapshots to true in my pluginRepository:

<pluginRepositories>
    <pluginRepository>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <id>central</id>
        <name>Maven Plugin Repository</name>
        <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
</pluginRepositories>

If you don't have the above in your pom.xml, just add it somewhere within <project></project>. And then change the version of the maven-shade-plugin to this:

<version>3.3.0-SNAPSHOT</version>

Upvotes: 1

Kenneth
Kenneth

Reputation: 138

FWIW...

You could also override the version of ASM, in order to make this work with maven-shade-plugin 3.2.x, like so:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.2.4</version>
  <dependencies>
    <dependency>
      <groupId>org.ow2.asm</groupId>
      <artifactId>asm</artifactId>
      <version>9.2</version>
    </dependency>
    <dependency>
      <groupId>org.ow2.asm</groupId>
      <artifactId>asm-commons</artifactId>
      <version>9.2</version>
    </dependency>
  </dependencies>
  ...
</plugin>

References: https://issues.apache.org/jira/browse/MSHADE-407

Upvotes: 0

Sarvar Nishonboyev
Sarvar Nishonboyev

Reputation: 13090

In my case, the latest version of maven was installed on my machine, and code was intended for the java 11 version. So I have used an older version of maven and the error didn't appear.

Upvotes: 0

Rocologo
Rocologo

Reputation: 604

I had to use this before I could use 3.3.0-SNAPSHOT

<pluginRepositories>
    <pluginRepository>
        <id>maven-snapshots</id>
        <url>https://repository.apache.org/content/repositories/snapshots/</url>
    </pluginRepository>
</pluginRepositories>

Upvotes: 8

tchristofferson
tchristofferson

Reputation: 303

@wemu was correct that the maven shade plugin doesn't yet support Java 16. To solve the issue I had to use a snapshot version of the maven shade plugin (3.3.0-SNAPSHOT) since 3.2.4 doesn't support Java 16 yet.

Upvotes: 8

Related Questions