Lombok log variable not found when running Junit - spring-boot

I am using Lombok for logging in my project. I have installed the Lombok plugin in IntelliJ and enabled Annotation processing. Now it do not show any errors in the source code. But when I run my Junit test, compiling is failing because it is not able to find log variable.
Following line in the class under test is causing error
log.info("Request received at /v1/employees");
What else do I need to do to support Lombok for unit tests?

Related

How lombok flag usage with WARNING?

I want to log the usage of the lombok feature #EqualsAndHashCode in my Vaadin / Spring Boot project. Therefor I add the file src/main/java/lombok.config with lombok.equalsAndHashCode.flagUsage=WARNING. [ BTW place this file in src/main/resources and assume its copied by maven into target classpath folder didn't work.]
If I set the configuration key to ERROR, the maven compilation failed with appropriate logs, mentioned the usage of the annotation #EqualsAndHashCode in certain files.
But HOW lombok act if this configuartion is set to WARNING ? I didn't see any warnings, neither during compile nor runtime ?

Generated test sources not getting invoked as part of the gradle build

Added Spring Cloud Contract plugin and configured it for baseClassMappings
Added Spring Cloud Contract verifier
Added required base classes for generated tests
Defined groovy contract
Using Test{useunitPlatform()} to identify and execute the JUnit tests
The contract tests are getting generated in the build/generated-test-sources but not being executed. I'm getting build successful without these contract tests being executed.
I'm using gradle 7.4 version and junit-jupiter-engine version 5.7.0.
I also had this problem in the past. I however solved it in maven since my project runs with that. There might be similar configuration properties in gradle. You can manually ride the configuration and in which files to look at.
<configuration>
<contractsRepositoryUrl>http://yourContractsRepositoryUrl.com</contractsRepositoryUrl>
<!-- We want to use the JAR with contracts with the following coordinates -->
<contractDependency>
<groupId>org.example</groupId>
<artifactId>example-artifact</artifactId>
<classifier>stubs</classifier>
</contractDependency>
<!-- The JAR with contracts should be taken from Maven remote -->
<contractsMode>REMOTE</contractsMode>
<includedFiles>
<includedFile>*filennameA*</includedFile>
<includedFile>*filennameB*</includedFile>
</includedFiles>
<contractsPath>your.contracts.package.structure</contractsPath>
<baseClassForTests>
org.someservice.contracts.ContractVerifierBase
</baseClassForTests>
<basePackageForTests>org.someservice.contracts
</basePackageForTests>
<testFramework>JUNIT5</testFramework>
I hope that there is an approach in there for you. It always unpleasant to get the contracts to run in my experience :(
This issue got resolved with these changes in my case:
I added this dependency group: 'org.junit.platform', name:'junit-platform-runner', version: '1.7.0' inside testImplementation in rest/build.gradle.
useJUnitPlatform() instead of useJUnit() in test section in rest/build.gradle
Changed the #RunWith(SpringRunner.class), to #RunWith(JUnitPlatform.class) in all the BaseClasses
Replaced the #Before with #BeforeEach in all the baseclasses.
Deleting .gradle and build temporary folders and rebuilding/regenerating sources helped me

Class of JDK can not be resolved in build.gralde file in Intellije Idea?

When I import Spring Framework source code into Intellij Idea, gradle build task run successfully. But I find build.gralde file in Intellij Idea show some error like bellow. Why String class can not resolved, the Test Unit can run successfully. How can I fix this.

Debugger, #SpringBootTest, and Gradle

I'm new to Spring Boot and Gradle and cannot figure out how to suspend JUnit tests and connect to them with a debugger.
I invoke the automated tests on the command line gradlew build. What I'd like is so the execution to pause wen it reaches the test task and wait for a debugger to connect.
The JUnit test classes are annotated like this:
#RunWith(SpringRunner.class)
#SpringBootTest
#ActiveProfiles("test")
#AutoConfigureMockMvc
I have tried adding the JVM arguments for debugging to the gradle.properties file and I still can't get it to suspend, much less listen on a port for the debugger. I'm not sure what information to provide you -- ask me in the comments for files, code, or settings.
Gradle 5.5
Spring Boot 2.16
Java 11
#Omid. Thank you for the link. The solution was simple.
UPDATE: Do not use gradlew build. Use the test task instead.
gradlew test --debug-jvm
In the Gradle 5.5.1 docs:
https://docs.gradle.org/current/userguide/java_testing.html#sec:debugging_java_tests

gradle build fails from terminal for lombok annotation in spring boot application

I am trying to generate war of spring boot application and using lombok for getter setter. Running gradle build command from terminal and getting error in all getter setter and constructors ie. can not find symbol. I am using STS and able run project successfully from sts. but from command line it throws 100s of errors. I have lombok dependency in gradle file.
Please help me to resolve this issue.
Thanks
It seems you need to set preprocessor for annotations in your build.gradle file. In STS or IntelliJ, the IDEs provide preprocessing for annotations. However when you want to build via command, you need to specify it in the build.gradle config.
dependencies {
annotationProcessor("org.projectlombok:lombok")
compileOnly("org.projectlombok:lombok")
}
Hope it helps! Happy Coding. :)

Resources