The method builder() is undefined for the type Filter

Getting the below error in Katalon Studio RC.

Error is : The method builder() is undefined for the type Filter

Code Snippet-
import browseRequest.Filter;
import browseRequest.OuterBrowseRequest;
import browseRequest.SortBy;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MServiceHelper {

private final Environment environment = new Environment();
private GlobalVariables globalVariables;

public MServiceHelper(GlobalVariables globalVariables) {
	this.globalVariables = globalVariables;
}

private static Filter createFormatFilter(String query) {
	return Filter.builder().field("FORMAT").query(query).build();
}

public void setFilterForBrowseRequest(String productName, OuterBrowseRequest outerBrowseRequest,String scenarioName, long parentFinancialAccountID1, long parentFinancialAccountID2,
String ediPartnerId, String fileName) {
	// add sapContractAccountId in browse Request file. This will be used in browse request in order to get files.

	List<Filter> filterList = new ArrayList<>();
	Filter ediPartnerIdFilter = Filter.builder().field("EDI_PARTNER_ID").build();
	ediPartnerIdFilter.setQuery(ediPartnerId);
	// parent financial account id
	Filter parentFinancialAccountFilter = Filter.builder().field("PARENT_ID").build();
	if("different PF_ID".equals(scenarioName)) {
		List<String> parentFinancialAccountIdList = new ArrayList<>();
		parentFinancialAccountIdList.add(Long.toString(parentFinancialAccountID1));
		parentFinancialAccountIdList.add(Long.toString(parentFinancialAccountID2));
		parentFinancialAccountFilter.setMultiquery(parentFinancialAccountIdList);
	}
	else {
		parentFinancialAccountFilter.setQuery(Long.toString(parentFinancialAccountID1));
	}

Filter Class :
import ebillingConsolidation.Daily
import internal.GlobalVariable
import lombok.AllArgsConstructor
import lombok.Builder
import lombok.Data
import lombok.NoArgsConstructor

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Filter {

private String field;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String query;
//String query;
@JsonInclude(JsonInclude.Include.NON_NULL)
private List<String> multiquery;

public void setMultiquery(List<String> multiquery)
{
	this.multiquery = multiquery;
}

public void setQuery(String query)
{
	this.query = query;
}

/* @Builder
public Filter(String field, String query) {
this.field = field;
this.query = query;
}
*/

}

Note - I have installed lombok 1.18.30 version and added as external jar file katalon.
In build.gradle file I have give as below,

 compileOnly 'org.projectlombok:lombok:1.18.30'
  annotationProcessor 'org.projectlombok:lombok:1.18.30'
  implementation 'org.projectlombok:lombok:1.18.30'
1 Like

Your code:

import browseRequest.Filter;
...
private static Filter createFormatFilter(String query) {
	return Filter.builder().field("FORMAT").query(query).build();
}

The message “The method build() is undefined for the type Filter” impiles that the Groovy Compiler could not find browseRequest.Filter class in the classpath. — Why the browseRequest.Filter class was not found? — It is because the source browseRequest.Filter class failed to compile. Why? — because the jar of lombok was not available in the classpath.

What did you do actually?

Did you manually download https://repo1.maven.org/maven2/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar and placed it in the Driver folder of your Katalon project? Possibly you didn’t. I guess you did:

  1. You wrote a build.gradle just as an usual Gradle Java project.
  2. You executed the command '$ gradle dependencies'. You found the jars you chose in the dependency tree emitted by Gradle.
  3. You naively thought that Katalon Studio will automatically include the jars into the classpath for your Groovy codes.
  4. You ran the the test case in KS. Then KS complained that it can not find the lombok jar in the classpath. You got puzzled.

I suppose, this is the story you experienced. Am I right?


Here I would assume I guessed right. Let me tell you something.

Katalon Studio will NEVER recognize any jars managed by Gradle as the implementation dependency and testImplementation dependencies declared in a build.gradle file.

In all Katalon Studio projects, you can find a file named .classpath. This is generated by Katalon Studio automatically everytime you open the project. @spalani.extern , please find it and look at it. I am sure, you would find the jar of lombock is missing in the .classpath file.

Katalon Studio requires you to place all external jar files of your choice in the Driver folder of your Katalon project. Katalon Studio will acknowledge the jars in the Drivers folder and register them into the runtime classpath for your test case scripts.

By the way, Katalon proposes a Gradle plugin named “Katalon Gradle Plugin”

If you use it, a new Gradle task katalonDependencies becomes available. This custom task will download the external jars into a temp directory on your local disk, generate some “fat”-jars, and copy the fat-jars into the “Drivers” folder.

As far as I see, this Gradle plugin rarely works successful. It tends to cause a lot of version conflicts between the jars bundled in Katalon Studio and the fat-jars you introduced into the Drivers folder. You must be very sure that the jar you put into the Drivers folder to be completely fit so that NO version conflicts to occur.

I am afraid your effort to use Gradle for your Katalon project will fail. I would warn you. You would waste your time. I would say so because I have ever tried a lot and failed.


If you want to use Lombok in a Katalon project, just download the jar into the Drivers folder of your project. The lombok jar has no external dependencies. It does not require indirect dependencies. Having the lombok jar in the Drivers foler, Katalon Studio will happily find the lombok.Builder class.

2 Likes

@spalani.extern

You want to use the Lombok library (Spice up your java: Automatic Resource Management, automatic generation of getters, setters, equals, hashCode and toString, and more!) in your Katalon project.

Interesting idea! I have never seen such a topic in this user forum.

This line in your build.gradle file looks most challenging.

This line works only for a Gradle project. Katalon Studio does not understand this. You have to find out how to register the Lombok as an Annotation Processor for the Groovy Compiler in Katalon Studio. You need to let the Groovy compiler be aware of the Lombok so that it is capable to process the special annotations like @Data, @Builder, @NoArgsConstructor and @AllArgsConstructor during it compiles the *.groovy sources to *.class.

… I don’t know how. I just guess, it would be impossible in a Katalon Studio project. As far as I know, Katalon Stuido offers users no chance to configure the Groovy Compiler inside KS.

I once created a Katalon project and examined if I can use Lombok. In the end, I couldn’t find the way. @Data and Build annotations were not preprocessed by the Groovy compiler in KS.

@spalani.extern

If you want to desparately need the Lombok, you should leave KS and go back to a plain old Maven/Gradle project. You seems to be a real programmer. You would be capable of developping a automated UI tests with Selenium WebDriver without KS. That would be easier for you.

Or simply, don’t use the Lombok annotations such as @Data and @Build. You should implement all getters, setters, constructors, equals and toString methods. You can write such code in Katalon Studio, of course.