Lombok annotations: compilation failure after merging - java

We have a rather large project, using maven, spring boot, querydsl, lombok.
I had 2 branches, both versions compiling successfully. (mvn clean compile) However, after merging, build fails, every of these compiler errors looks like lombok did not run correctly - errors are like cannot find symbol [ERROR] symbol: variable log with log generated by #Sl4j or cannot find getXyz() on a class instance with #Getter.
I don't even know where to start here, so any hint on how to pin down that error would be great. And, of course, what further information do you need to help?
EDIT
Thanks for the hints so far, I now tried to adapt our pom.xml configuration so that lombok is triggered by maven-compiler-plugin's annotationProcessorPaths -
My new pom.xml / plugin config is:
<build>
<pluginManagement>
<plugins>
<!-- maven dependancy update management plugins-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.0.5</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<excludes>
<exclude>org.apache.commons:commons-collections4</exclude>
</excludes>
</configuration>
</plugin>
<!--querydsl configuration-->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/querydsl</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>
<arg>-Aquerydsl.entityAccessors=true</arg>
<arg>-Aquerydsl.useFields=false</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</path>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
<version>${querydsl.version}</version>ΓΈ
</path>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</path>
<path>
<groupId>com.mysema.codegen</groupId>
<artifactId>codegen</artifactId>
<version>0.6.8</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
This config compiles the version before the problem occurred; However, the build error with the post-merge version remains the same. Is my lombok config incorrect?

Actually, our pom.xml setup was perfectly fine. However, during merge, git duplicated an hibernate
#EntityListener annotation. As a result, lombok somehow... stopped working? When I removed one of the annotations, everything was fine again.
Would there have been a way to detect this Problem, like lombok logs?

Related

How to fix vulnerability maven-core 3.0 in exec-maven-plugin

I have a spring boot project with maven.
The POM.XML for a certaun service looks like this:
[...]
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</dependency>
[...]
<build>
<plugins>
<plugin>V
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${version.spring-boot-maven-plugin}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${version.org.codehaus.mojo}</version>
<executions>
<execution>
<id>Run-SQL-create</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>[...].CreateSQLSeedingFile</mainClass>
<arguments></arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven-compiler-plugin}</version>
<configuration>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${version.lombok-mapstruct-binding}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${version.mapstruct-processor}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${version.org.projectlombok}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
I ran [dependency-check-maven] to scan for vulnerabilities.
It found CVE-2021-26291
Using mvn dependency:tree I found that it is inside the exec-maven-plugin
In the details it mentions:
If you are currently using a repository manager to govern the repositories used by your builds, you are unaffected by the risks present in the legacy behavior
However we do not have a repository manager (it's just a small project).
And I can not upgrade the version, since the dependency exec-maven-plugin is already at the latest version 3.0.0
Now when I remove the dependency completely (not even sure what I'd have to solve then!) it finds the same vulnerability in maven-core-3.1.1 inside spring-boot-maven-plugin
Here the same goes: it is already at the latest version 2.6.2
Is there a way this vulnerability, without using a repository manager ?

Proper Lifecycle Order For Annotation Processing In Maven

I'm currently working on a java project where I need to generate and compile JPA metamodel classes as part of the build. I did some research and found an answer here: Generate the JPA metamodel files using maven-processor-plugin - What is a convenient way for re-generation? that seems like a reasonable solution. The problem is, my project also contains some groovy classes that need to be compiled alongside the java. If I enable the maven-processor-plugin, the maven build will fail as soon as it encounters a java class that depends on a groovy class. Looking at the console output, I can see that maven-processor-plugin is running before the groovy compiler, so those groovy classes have not had a chance to be compiled.
Does anyone know if there is a good way to handle this? Is there some way to break the compilation process up into stages so that I can control what gets processed when?
Here is a snippet of my pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showWarnings>false</showWarnings>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.6.0-03</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.7-02</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5-jdk8</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/../src/main/generated-sources/java/jpametamodel</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.13.Final</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/../src/main/generated-sources/java/jpametamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
After a good bit of trial and error I finally found a solution that seems to work. maven-processor-plugin can use include/exclude filters to limit the scope of the files it looks at. I added an includes filter that restricts the processing to my domain classes. Now when I build it can process my annotated classes without getting hung up on the groovy files.
My final result ended up looking like this:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5-jdk8</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<includes>
<include>com/tura/product/domain/*.java</include>
</includes>
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.13.Final</version>
</dependency>
</dependencies>
</plugin>

Maven & JaCoCo - How do exclude a class from the report that's brought in from a dependency?

I'm adding JaCoCo to a project and i'm struggling to have it exclude a class (that's been brought in via a dependency) from the report for a submodule. This is the error i'm getting:
Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.7.1:site (default-site):
Error generating jacoco-maven-plugin:0.8.4:report:
Error while creating report:
Error while analyzing ~/proj/submod/target/classes/mydep-jar-with-dependencies.jar#com/jlb/proj/pkg/MyClass.class. Can't add different class with same name: com/jlb/proj/pkg/MyClass
And the jar in question is brought into the submodule like this:
<dependencies>
<dependency>
<groupId>com.jlb.pkg</groupId>
<artifactId>mydep</artifactId>
<version>${revision}</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
</dependencies>
The jacoco reports are generated via a block in the project's overall parent POM, however i've added an override into the submodule in question here, that should exclude the class (the version of the class from the dependency) its complaining about, but it's having no effect:
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
<report>report-integration</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<excludes>
<exclude>**/com/jlb/proj/pkg/MyClass.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</reporting>
So how do I exclude the offending class from the report?
Please try where com.jlb.pkg should be your base package
tie the jacoco report generation with your test phase of your maven build
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<includes>
<include>com/jlb/pkg/**/*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
So, it was specifically in the jacoco exec for the integration tests where the conflict was occuring, but in the reporting section, i've added the include there, that should exclude any classes coming in from JARs:
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<includes>
<include>com/jlb/**/*.class</include>
</includes>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report</report>
<report>report-integration</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

How to generate toString method with jaxb2?

I would like to overload the toString methode from my wsdl.
In my pom.xml
I add that in the dependencies :
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>1.11.1</version>
</dependency>
I added this plugin in the build/plugins
Blockquote
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.build.directory}/wsdl/META-INF/wsdl/</schemaDirectory>
<schemaIncludes>
<include>FrameworkGedServiceMetier.wsdl</include>
</schemaIncludes>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-Xcopyable</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>1.11.1</version>
</plugin>
</plugins>
</configuration>
</plugin>
I build maven is successful but I don't have my method toString in the class.
To inspirate me i use this documentation
I think there is a problem with that version. Please try:
<version>0.12.0</version>
(It looks like 1.11.1 was published by mistake.)

maven aspectj weaving NullPointerException

I have a Spring MVC application made with MyEclipse, which contains generated sources as well as my own sources, plus aspects that I defined on the generated classes. Everything compiled fine in MyEclipse, but I want now to switch to Maven in order to use a continuous integration server.
I have been fiddling with the pom.xml for a long while now, and I hit a wall I can't seem to get around. When maven gets to the moment of weaving aspects, I get the following exception (just the first few lines for brevity):
[INFO] [aspectj:compile {execution: default}]
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[ERROR] ABORT
May 30, 2016 11:48:05 AM org.aspectj.weaver.tools.Jdk14Trace info
INFO: Dumping to /var/atlassian/application-data/bamboo/xml-data/build-dir/OW-BUIL-JOB1/./ajcore.20160530.114805.876.txt
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] AJC compiler errors:
abort ABORT -- (NullPointerException) null
null
java.lang.NullPointerException
at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.resolveAnnotations(AnnotationDiscoveryVisitor.java:238)
at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.visit(AnnotationDiscoveryVisitor.java:217)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1348)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:748)
...
My pom.xml is too long to paste it here, but the build part is as follows (let me know if you want to see some of the dependencies):
<build>
<directory>bin</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src</source>
<source>generated</source>
<source>resources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<excludes>
<exclude>main/</exclude>
<exclude>test/</exclude>
</excludes>
<useIncrementalCompilation>true</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.6</source>
<target>1.6</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.6</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${project.basedir}/WebRoot/WEB-INF/web.xml</webXml>
<warName>oligoWorld</warName>
<outputDirectory>${project.basedir}</outputDirectory>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>[1.8,)</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Anybody seeing anything wrong or missing that might cause that exception? FYI, the version of my aspectj dependencies (aspectjrt, aspectjtools and aspectjweaver) is 1.8.7.
I seem to have found the problem. In the pom.xml I had the dependency for aspectjtools listed with all the other dependencies in the dependencies section of the pom file, outside the aspectj-maven-plugin definition. Instead, I moved it inside the plugin; also, I changed the aspectj libraries' version to 1.8.9, as it seems 1.8.7 exhibits a bug similar to what I have found. After this, everything worked. So here's my modified definition for the aspectj-maven-plugin for reference:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<dependencies> <!-- The change that fixed it starts here... -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies> <!-- ...and ends here. -->
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.6</source>
<target>1.6</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.6</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</plugin>

Categories