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 ?
Related
I have file src/main/resources/dev/important.properties where in fact 'dev' is one of Spring profile names I use.
Somewhere in application this file is referenced as:
#PropertySource(value = "classpath:important.properties")
When I run in Intellij:
mvn spring-boot:run -Dspring-boot.run.profiles=dev
I get FileNotFoundException upon application start. If I move file one level up (to src/main/resources) it works. I can say no surprise here. How to add src/main/resources/dev to classpath so this file would be visible in this directory? This stuff is needed only for local development (Maven+Intellij and dev profile) and it's excluded from runnable jar. I do not want to modify #PropertySource expression.
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?
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. :)
Hi guys I have a problem in IntelliJ IDEA. I have a configuration for run my application. When I run it somes libraries added like dependencies in my module and defined with scope "Provided" are not added to classpath and give me a class not found exception.
If I change the scope from "Provided" to "Compile" it does work.
But i'm not sure it is right becouse in my pom.xml they are configured with scope "Provided" and when I run maven configuration the dependencies are changed to "Provided" in project structure and it does not work again.
My question:
Is there a way to include some dependecies in classpath during run without changing the scope in pom.xml?
IntelliJ IDEA 2018.1 has an option to include the dependencies with the provided scope into classpath, it's available for some run/debug configurations, like Application and Spring Boot.
I fail to understand why in the following minimal project my implementation of Spring's WebApplicationInitializer interface is found when running tests within Eclipse and IntelliJ, but not when using Maven (mvn clean test).
With Eclipse and IntellIJ I see INFO: Spring WebApplicationInitializers detected on classpath: [com.example.pack.DummyInitializer#26d678a4]
With mvn clean test I see INFO: No Spring WebApplicationInitializer types detected on classpath.
In the test I start an Embedded Tomcat:
String pathToWebXML = new File("src/main/webapp/").getAbsolutePath();
tomcat = new Tomcat();
tomcat.setBaseDir("embedded_tomcat");
tomcat.setPort(0);
tomcat.addWebapp("", pathToWebXML);
tomcat.start();
The web.xml references a ServletContextListener implementation which creates a new (and empty) AnnotationConfigWebApplicationContext.
I uploaded the example project to GitHub: https://github.com/C-Otto/webapplicationinitializer
As indicated in the comments, the classpath used by Maven Surefire (and Maven Failsafe) in the default setting is not scanned by Tomcat. Most classes are referenced using a MANIFEST.MF file inside a JAR file.
One option is to disable the useSystemClassLoader setting of the Maven plugins. However, this changes the details of the classloader, which may cause other problems.
As another option one could disable useManifestOnlyJar, which may cause problems on Windows machine.
In our project we decided to remove the initializer classes, and instead register whatever they were supposed to do manually. In a concrete example, as our implementation of AbstractSecurityWebApplicationInitializer was not found, we now register the security filter manually inside the contextInitialized method:
String filterName = AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);
servletContext.addFilter(filterName, new DelegatingFilterProxy(filterName)).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
You can tell Tomcat to include the jars that are referenced via the manifest file in the jar created by surefire. This can be done in context.xml setting the Jar Scanner attribute scanManifest to true. This is the default in newer versions of Tomcat as stated here: https://bz.apache.org/bugzilla/show_bug.cgi?id=59961.