Lombok with Netbeans/Maven Annotations are not Recognized/Working - maven

I tried to update my existing Lombok version 1.16.16 to 1.18.2 in Netbeans 8.2 (maven multi-module project).
Unfortunately, all versions higher than 1.16.18 are not working. No annotation is recognized and I get compile errors in the IDE. The pure maven build is working.

You have to configure the maven compiler plugin. Add the following snippet to the build section of your pom (at best to your parent pom or to each project which is using Lombok).
If you already have a configuration of the build plugin in your pom make sure to add the <annotationProcessorPaths> section.
This will ensure that Lombok is available during the compiling process to manipulate the AST.
pom.xml - snippet
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
...

Related

Running Selenium(TestNG) tests from Azure Devops

I'm working on running my automation test scripts (which is a Maven project
based on java and using test ng ) in AzureDevops CI/CD pipeline. I have pushed all my code to Github and created a Maven task to run the tests.
But when I try to run the Maven task , it is not considering testng.xml, where I have all the tests configurations like which tests to be run(order of the tests) and other configuration stuff like listener to create some custom reports. It is just running all the test classes present in my complete Maven project.
Please help me which config / task I should in add in my build inorder for the test to run based on my testng.xml
Below is the Pom.xml
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
TestAutomation
Test
0.0.1-SNAPSHOT
jar
Test
http://maven.apache.org
org.seleniumhq.selenium
selenium-java
3.14.0
org.testng
testng
6.11
compile
org.apache.poi
poi
3.16-beta2
com.relevantcodes
extentreports
2.41.2
commons-io
commons-io
2.6
log4j
log4j
1.2.17
com.googlecode.json-simple
json-simple
1.1.1
<!-- for gson https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>listener</name>
<value>com.qa.ExtentReportListner.ExtentRerportListener</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>

Protoc Version 3.2 java files

I have compiled my Protoc file using protoc 3.2 compiler. When i try to use it with maven dependency shown below, POM file is giving me error and all of the dependencies were not resolved. Wondering what is the right version of grpc-all i should be using that is compatible with Java code generated with protoc compiler 3.2.0
My pom file looks like:
<dependencies>
<!-- https://mvnrepository.com/artifact/io.grpc/grpc-all -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
Also, the error i am getting is,
Turn out to be Maven issue,
Maven clean
Maven install fix that for me.

Annotation processor is not being invoked by the maven compiler plugin

I have written my annotation processor as a separate maven project, it contains my custom annotation and its processor. I have added this project as a dependency to a project where the classes have been annotated with the custom annotation. I want this processor to be invoked as part of the maven build.
Following is the pom snippet -
<!-- Compiler configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>com.test.processor</groupId>
<artifactId>processor</artifactId>
<version>1.0.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<!-- dependency for processor project -->
<dependencies>
<dependency>
<groupId>com.test.processor</groupId>
<artifactId>processor</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
But the problem is that, the annotation processor is not getting triggered. Am I missing something or doing anything wrong.
Kindly guide me on this.
Try switching to a newer version of the maven-compiler-plugin.
I'm using 3.6.1 with the same configuration as you and it works.

Installing and compiling Maven artifacts on Java 8

I have a project with a pom.xml that has the following <build> declaration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
When I run mvn install on this project, it compiles the project, runs unit tests and publishes it to my local repo. I am trying to learn a little more about Maven here, and am having a tough time finding documentation/explanations on the following:
How am I able to run mvn install, if the POM doesn't declare it under build/plugins? Does maven-compiler-plugin include maven-install-plugin, if so, how could I have figured that out?
Most importantly: the value of build/plugins/plugin/configuration/source and .../target are both set to 1.8. If my machine has Java 8 on it, and I run mvn install on this project without any errors, does that guarantee that the project builds with Java 8? I'm looking at the docs for the Compiler Plugin and don't see those source/target configs listed anywhere.
First you should learn what the build life cycle is and how it works and how the plugins are bound to the life cycle by default.
Furthermore you should understand that in Maven every project inherits from the super pom file which is part of the maven distribution (the package you have downloaded). The super pom defines the default folder layout and some versions of plugins.
The question to define the maven-compiler-plugin as you did is to be very accurate simply wrong. You should have defined it like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This would overwrite the definition which is inherited by the super pom and changes it's configuration. In your case i would suggest to change the definition into this:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
..
</project>
The encoding should be set globally cause there are other plugins which use this definition like the maven-resources-plugin. The usage of the above property simplifies this, cause every plugin which has an option for encoding will use the default as defined in the property.
To be sure using the correct version of Java (your JDK on your machine) you have to use the maven-enforcer-plugin.
Apart from that please take a look onto the plugins page which shows the most up-to-date releases of the plugins.
As a good documentation i can recomment the Books on Maven but be aware they are written with Maven 2 in mind. So if something is not clear ask on users mailing list of here on SO.

Maven Install: "Annotations are not supported in -source 1.3"

When running mvn install on my project, i see it fail due to the following errors:
C:\Repositories\blah\src\test\java\com\xxx\qm\testrunner\test\ATest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
C:\Repositories\blah\src\test\java\com\xxx\qm\common\test\BTest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
My Maven dependency includes jUnit 4.8, however and has no reference to 1.3 anything.
What would cause these errors? Please advise
You need to specify the source version of your maven project through the use of the maven-compiler-plugin. Add the following to your pom build element and set the appropriate java source and target levels.
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/plugins/maven-compiler-plugin/
A shorter version:
<project>
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
....
You are most likely using OpenJDK where the source level is 1.3 when not explicitly set - as opposed to Oracle JDK where the source level is 1.5.
Since most modern Java projects target newer code than Java 5 you most likely need to set this anyway.
Also note that if you need a lower target than source (e.g. for compiling with Java 6 but deploying to Java 5) you can do this by using the Eclipse compiler instead of Javac.
Bu default, the maven tries to compile using Java 1.3 version. I hope most of them hit this error because of missing to tell maven that "Hey Maven, Dont use 1.3 and use "whatever_version_I_give"
This can be mentioned in pom.xml as below :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
In my above example, I have used 1.7. Please replace with whatever version you wish to.
Add this in your pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Resources