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

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. :)

Related

Springboot not recognized on IntelliJ

Even after installing Java and Maven, creating a spring project from springinitializr is facing an issue. The issue is that the project is not recognised as spring project, the annotations, import nothing are working. Can anyone please help out
I tried to redo the process, but things were same. Is any settings.xml needs to be made but I don't see it as necessity.
When opening your project in intellij. you should do so via the import > new Project and choose the pom.xml for the generated project from spring initialize. This way it can resolve dependencies and properly open your project.
if the problem persists you can go to your MainApplication.java > right click > run as spring boot project.
If it does not put the configuration on the run shortcut on the up right of the application you can configure it by adding the command : mvn spring-boot:run and add other configurations id desired.

Spring Boot Dependency

Why this error occurs every time while I import a spring boot project?
It is due to missing of dependencies.
Use mvn clean install from command line before importing project to eclipse.
Also, this question can help - Eclipse showing "Maven Configuration Problem: Unknown"

How to add a runtime library on Gradle in the build command

I have a build.gradle file that I want to use to build a Spring Boot microservice for multiple projects. I have created a custom library with some classes that should not be in all of the projects but I don't want to have to edit the build.gradle file when I build the microservice depending on which project I will use it in.
How can I add a command/parameter to gradle build that can add runtime libraries to the Spring Boot app?
Something like (just an exaple):
gradle buildDocker -PaddRuntime=com.skios.lib:lib-common:0.2.35
Thanks for any directions
I am not sure I understand your issue fully and thus not convinced this is the best solution.
But since a Gradle build script accepts code, you can have conditionals in a dependencies block:
dependencies {
if (project.hasProperty('addRuntime')) {
runtimeOnly('com.skios.lib:lib-common:0.2.35')
}
}
and then on the command line: ./gradlew buildDocker -PaddRuntime

Spring Boot 1.4.3 Embedded Tomcat NoSuchMethodError StringManager.getManager

I have update my project to use Spring BOOT 1.4.3. The code compiles and runs without issues from Eclipse Neon 1.
But when I run from command line
mvn clean install -DskipTests
java -jar myweb\target\my-web-1.0-SNAPSHOT.jar
I get runtime error and tomcat is not starting
Caused by: java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager;
at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:43) ~[tomcat-embed-core-8.5.6.jar!/:8.5.6]
Please can you tell why? How to find which tomcat is used at runtime, as my understand is that 8.5.6 is having compile scope(?)
Please help. If the suggestion is to use tomcat.version in properties of POM file or add tomcat-juli dependency, then please help me understand why it is required?
Impatient stackoverflow'ers dont just flog new comers only because you can do. You can easily ask if you want my POM, but I used just spring-boot-starter-web thats it.
For this kind of problem, it's often due to multiple jar having the same class inside your classpath, so :
Find where this class / method could come from, by opening the type popup (CTRL + SHIFT + T in Eclipse). It will display you every jar in your classpath that contains the class.
Open the class in each jar to see which one contains your method and which one don't.
Display the dependency hierarchy of your project with mvn dependency:tree
If the 2 jars are in your classpath, you might exclude the one that don't contain the method.

Query Regarding Maven Aspectj

I’m using AspectJ in my project. My project is based on Maven.
I’m able to successfully compile the .aj file and when I try to run the testcase using maven my aspects are working fine.
But when I start executing the program from command prompt (eg.. java <*.jar>) my aspects are not working. Is it necessary to set any Java JVM option for my aspect to execute.
Thanks In Advance

Resources