Gana
Gana

Reputation: 492

How to get eclipse libraries compiled on Java 8

Let me begin with the error I see and then I will explain the case followed by:

<p style="color:red">
EclipseJDTUtil.java:[3,34] cannot access org.eclipse.core.resources.IProject
  bad class file: C:\Users\ram\.m2\repository\org\eclipse\platform\org.eclipse.core.resources\3.15.0\org.eclipse.core.resources-3.15.0.jar(org/eclipse/core/resources/IProject.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
</p>

My project has a dependency on org.eclipse.jdt.core library.

<dependency>
        <groupId>org.eclipse.jdt</groupId>
        <artifactId>org.eclipse.jdt.core</artifactId>
        <version>3.23.0</version>
    </dependency>

I built my project with JRE8. I used maven plugin to point to the right version at compilation like below.

<plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
</plugin>

It has been OK all these days but suddenly from past few days, I see below error. I understand that this library is now available with source compiled on java 11 which is causing issues to my project. But, how is that possible? When the project source is at java 8, the dependencies should not be downloaded for java 11.

I am not in a position to update my whole project to new java version!

What I need is the eclipse libraries compiled on java 8. How should I get them on maven build? What configuration will make it possible?

Edit 1: (Response to Andreas comment):

@Andreas: Superb. As you pointed out correctly, it is pulling org.eclipse.core.resources: 3.15.0, as shown in the error. As you suggested I have added version for "resources" like below:

<dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.eclipse.platform</groupId>
    <artifactId>org.eclipse.core.resources</artifactId>
    <version>3.12.0</version>
    <scope>compile</scope>
  </dependency>
</dependencies>

After I maven build I see below error now.

<p style="color:red">
EclipseJDTUtil.java:[8,32] cannot access org.eclipse.core.runtime.IPath
  bad class file: C:\Users\ram\.m2\repository\org\eclipse\platform\org.eclipse.equinox.common\3.15.0\org.eclipse.equinox.common-3.15.0.jar(org/eclipse/core/runtime/IPath.class)
    class file has wrong version 55.0, should be 52.0
</p>

I am also attaching Dependency Hierarchy screenshots.

enter image description here after adding version for resources

Upvotes: 2

Views: 1426

Answers (2)

xogoxec344
xogoxec344

Reputation: 103

I just ran into a very similar issue. Managed to get it working again by downgrading from

        <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>org.eclipse.jdt.core</artifactId>
            <version>3.27.0</version>
        </dependency>

(which worked fine under java 8 up to a few weeks ago) to:

        <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>org.eclipse.jdt.core</artifactId>
            <version>3.10.0</version>
        </dependency>

which seems to still work fine with java 8, at least for the AST functionality I'm using in my project.

Upvotes: 2

Kevin Hern&#225;ndez
Kevin Hern&#225;ndez

Reputation: 844

Based on the answer of @KC_911723 and @grubi you can use this configuration:

<dependencies>
    <dependency>
        <groupId>org.eclipse.jdt</groupId>
        <artifactId>org.eclipse.jdt.core</artifactId>
        <version>3.23.0</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <!-- declare the exclusion here -->
                <groupId>org.eclipse.platform</groupId>
                <artifactId>org.eclipse.core.runtime</artifactId>
            </exclusion>
            <exclusion>
                <!-- declare the exclusion here -->
                <groupId>org.eclipse.platform</groupId>
                <artifactId>org.eclipse.equinox.common</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.eclipse.platform</groupId>
        <artifactId>org.eclipse.core.runtime</artifactId>
        <version>3.13.0</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <!-- declare the exclusion here -->
                <groupId>org.eclipse.platform</groupId>
                <artifactId>org.eclipse.equinox.common</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.eclipse.platform</groupId>
        <artifactId>org.eclipse.equinox.common</artifactId>
        <version>3.14.100</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

or use this gradle configuration:

dependencies {
    implementation ('org.eclipse.jdt:org.eclipse.jdt.core:3.23.0'){
        exclude group: 'org.eclipse.platform', module: 'org.eclipse.core.runtime'
        exclude group: 'org.eclipse.platform', module: 'org.eclipse.equinox.common'
    }
    implementation ('org.eclipse.platform:org.eclipse.core.runtime:3.13.0'){
        exclude group: 'org.eclipse.platform', module: 'org.eclipse.equinox.common'
    }
    implementation 'org.eclipse.platform:org.eclipse.equinox.common:3.14.100'
}

Upvotes: 0

Related Questions