简体   繁体   中英

Eclipse reporting "the value of the field is not used" warning even though Lombok enable

I have 2 classes in a Eclipse project.

package com.example;

import lombok.Getter;
import lombok.experimental.Accessors;

@Accessors(fluent = true)
@Getter
public class MyBean {
    private String value = "aaa";
}
package com.example;

public class MyClass {
    public static void main() {
        System.out.println(new MyBean().value());
    }
}

After building, Eclips reports "the value of the field value is not used" for MyBean class and "The method value() is undefined for the type MyClass" even though Eclipse's content assist shows MyBean#value() method, there are no warnings before building, and compilation, execution both are finished successfully. So I guess Lombok works properly and the problem is Eclipse doesn't recognize Lombok.

Here are what I tried and found.

  • attaching lombok.jar to Eclipse and checking eclipse.ini
  • cleaning and rebuild the project
  • removing Lombok dependency from maven local repository then reinstall
  • the problems only occur in this project. Eclipse handles other projects with lombok properly (and all projects belong in the same workspace).
  • I cannot reproduce these problems in other projects.

Any ideas?

Finally, the problems are solved by just creating new project and moving all sources and resources to it. It seems that Eclipse's project configurations were broken I don't know why.

I install lombok on eclipse(java -jar lombokxxxx.jar) and the problem disapear.

Lombok API Configuration

Note: Lombok version may change. Present we are using 1.18.24

  1. Goto -> C:\Users\Udaykiran.Pulipati.m2\repository\org\projectlombok\lombok\1.18.24
  2. A Lombok configuration window will open > Click on Specify location button
  3. Select eclipse.exe root folder where it is located(installed)
  4. Selecting eclipse.exe root folder > D:\eclipse\jee-2021-06\eclipse
  5. Click on Install / Update button in Lombok configuration window
  6. Click on Quite Installer
  7. Restart Eclipse IDE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM