Experiencing an issue while trying to generate methods using lombok. The issue is "The method / constructor / etc is undefined for the type ...". I encounter it for any classes that are located in src/main/java, but, when using the same one in src/test/java, during testing I dont get any errors and the results are correct. Let me explain the situation a bit more:
if I try to use a generated method inside another class in src/main to get some data it throws an error about undefined method.
When I remove lombok methods and write my own, there are no issues whatsoever.
The error is not present if I use lombok generated methods inside classes in src/test/java directory
Code snippet:
public class DroolsRuleParsing {
public static String checkLombokMethods(RuleFormat rule) {
String constraintItems = null;
if (rule.getRuleType().equalsIgnoreCase("item")) {
constraintItems = "$hit_idList contains $appliedrule_hitId";
}
if (rule.getRuleType().equalsIgnoreCase("hit")) {
constraintItems = "$hit_id == $appliedrule_hitId";
}
return constraintItems;
}
}
Error: The method getRuleType() is undefined for the type RuleFormat
If I remove this method and try to use .getRuleType() in src/test/java, then there are no errors:
@Test
public void testRuleGeneration() throws Exception {
LOG.info("Testing rule generation from JSON");
RuleFormat RuleData = new RuleFormat();
RuleData.setId("unique_id_4");
RuleData.setUid("rule_4");
RuleData.setName("Rule 4");
RuleData.setVersion("ver1");
RuleData.setRuleType("item");
LOG.info("check lombok getters {}", RuleData.getRuleType());
2024-09-26 17:06:12,572 [main] INFO check lombok getters item
I am using mvn clean test; mvn clean install to check if created method works.
I've tried:
following sintallation guide on the official website to install Lombok - https://projectlombok.org/setup/maven - instruction here
fiddled with configuration in pom file, some adviced to remove "scope" from the pom.xml - did not help
reinstalling VS code extensions with Lombok (Lombok Annotations Support for VS Code)
As I was using a test project from Drools "Getting started" section, the packaging value in pom.xml was set to kjar. With this setup lombok methods are not working and I was not able to make them work. Switching packaging to jar solved an error, though Drools rules stopped working in the same project.