Lombok compilation error on Jenkins - java

I am trying to introduce Lombok into my project. Everything builds fine when I compile it locally but on Jenkins it reports this problem and then it fail on all the getters and setter which I replaced with #Data anotation. Jenkins uses Java 1.8. Any idea what might be wrong?
[INFO] Compiling 154 source files to /var/lib/jenkins/jobs/MERGE REQUEST build error_prone/workspace/com.betradar.betpal.server.app.api/target/classes
/var/lib/jenkins/jobs/MERGE REQUEST build error_prone/workspace/com.betradar.betpal.server.app.api/src/main/java/com/betradar/betpal/server/app/message/ObjectFactory.java:22: warning: lombok.javac.apt.LombokProcessor could not be initialized. Lombok will not run during this compilation: java.lang.IllegalArgumentException: com.google.errorprone.MaskedClassLoader$1$1 extends com.sun.tools.javac.file.JavacFileManager
public class ObjectFactory {
^
at lombok.javac.apt.LombokFileObjects.getCompiler(LombokFileObjects.java:148)
at lombok.javac.apt.InterceptingJavaFileManager.<init>(InterceptingJavaFileManager.java:40)
...

Errorprone uses the java9 compiler under the hood. There are two possible solutions:
Upgrade the Lombok dependency to 1.16.20
Downgrade the errorprone dependency

Related

Gradle XJC generate equals and hashCode methods

The project has a gradle module to build JAX2B classes.
The XJC configuration already uses annotations:
bindingFiles = project.files("$projectDir/src/main/resources/binding.xjb",
"$projectDir/src/main/resources/annotations.xjb")
// Needed to execute custom annotations
options.add("-Xannotate")
}
I thought I could add options to get equals() and hashCode()
xjc {
bindingFiles = project.files("$projectDir/src/main/resources/binding.xjb",
"$projectDir/src/main/resources/annotations.xjb")
options.addAll("-Xannotate", "-Xequals", "-XhashCode")
}
The methods are not on the class and there are no errors or warnings in the build log.
How do I generate those methods?
PS: Here are the build file dependencies
dependencies {
implementation(project(":xxx:xxx-api"))
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.2")
xjcPlugins("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.2")
xjcPlugins("org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.1.0")
}
UPDATED
Thanks to #thokuest for spotting a missing dependency.
The project has a gradle module to build JAX2B classes, but I'm getting build errors adding the "-Xequals" option:
build/generated/sources/xjc/java/org/pen/ProductOutputType.java:16: error: package org.jvnet.jaxb2_commons.locator.util does not exist
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;
^
build/generated/sources/xjc/java/org/pen/ProductOutputType.java:47: error: cannot find symbol
public class ProductOutputType implements Equals2
^
I've created a minimum example as a gist -- build.gradle.kts
equals() and hashCode() are contributed by the jaxb2-basics plugin.
xjcPlugins 'org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1'
According to the project's wiki, there's a runtime dependency to org.jvnet.jaxb2_commons:jaxb2-basics-runtime:1.11.1 that you would need to add as well.
Update
Dependency org.jvnet.jaxb2_commons:jaxb2-basics-runtime:1.11.1 must be in scope implementation as otherwise a build error as described in the question occurs.

Getting compilation error while using #Slf4j in Lombok in Eclipse

Building the project using gradle in eclipse after Using #Slf4j annotation of lombok is throwing below error :
Task :compileJava FAILED
error: cannot find symbol
log.trace("logging now");
^
symbol: variable log
But it is generating the .class file with the log variable correctly : private static final Logger log = LoggerFactory.getLogger(NetsuiteWebSecurityConfig.class);
There is no problem with the #Data lombok annotation. It is generating getters/setters in .class file and also not throwing any error .
Note : i referred this Cannot make Project Lombok work on Eclipse (Helios) for lombok installation . I can say lombok is working because it is generating the code in .class file . Not sure why it is failing while giving gradle build
I installed lombok correctly and set the annotations processor. But still nothing worked . What i have done is created a new folder at another place and cloned my git repository freshly there. To my surprise it worked . Dont know how , but the trick worked .

warning: unknown enum constant Status.STABLE

In the quest to solve this and somehow that, I was trying out to create packages to subdivide main and test classes and then to make use of compiler with added modules to execute the unit-tests. Not a very good way agreed, but just a hypothetical structure for now.
Few open questions as I proceeded further were:-
Add a JDK9 based module to the project.
Add JUnit5 to the classpath using IntelliJ's shortcut. (lib folder) [junit-jupiter-api-5.0.0.jar]
Q. Note that it brings along the opentest4j-1.0.0.jar to the lib/ folder. Why is that so, what is the other jar used for?
Add the classes and generate some tests method correspondingly.
Compile the sample project (shared just to draw a picture of the directory structure in use) using the command
javac --module-path lib -d "target" $(find src -name "*.java")
Results into warnings as -
warning: unknown enum constant Status.STABLE
reason: class file for org.apiguardian.api.API$Status not found
warning: unknown enum constant Status.STABLE
2 warnings
Note:-
I find the usage of junit-jupiter suspicious since if I comment out the code using JUnit and execute the same command, things seem to be working fine.
Libraries/Tools used if that might matter:-
junit-jupiter-api-5.0.0 with
Java version "9" (build 9+181)
IntelliJ 2017.2.5
Q. What could be a probable cause to such a warning? Moreover, I am unable to find the API.Status in my project and outside the project classes as well.
The compilation warning can simply be ignored. Moreover, it won't be appearing anymore starting with the version 5.1.0 (currently in development). It is all explained in Release Notes:
In 5.0.1, all artifacts were changed to have an optional instead of a mandatory dependency on the #API Guardian JAR in their published Maven POMs. However, although the Java compiler should ignore missing annotation types, a lot of users have reported that compiling tests without having the #API Guardian JAR on the classpath results in warnings emitted by javac that look like this:
warning: unknown enum constant Status.STABLE
reason: class file for org.apiguardian.api.API$Status not found
To avoid confusion, the JUnit team has decided to make the dependency to the #API Guardian JAR mandatory again.
For reference also see:
Remove compile dependency on apiguardian-api in Maven POMs
Reintroduce compile dependency on apiguardian-api in Maven POMs
1) opentest4j
opentest4j is a transitive dependency of junit-jupiter-api. See the dependency graph:
+--- org.junit.jupiter:junit-jupiter-api:5.0.1
+--- org.opentest4j:opentest4j:1.0.0
\--- org.junit.platform:junit-platform-commons:1.0.1
2) unknown enum constant Status.STABLE
You need to add following dependency: apiguardian-api.
For example in Gradle, you can do it via:
dependencies {
testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.1'
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
}
But overall, dependency is build-tool-independent, so you can do it in plain IDE without Gradle, or Maven.

Missing dependency 'class javax.annotation.Nullable'

I was trying to use the jira-rest-java-client provided by Atlassian in a Scala program I am developing. I am using Eclipse as my IDE.
When I have an object of type Issue and I try to look at the properties I see there are far fewer properties than are declared in the Java code.
I thought perhaps this was just Eclipse not finding all properties/methods of an object so I tried putting Issue.getSummary() and doing an sbt compile. The compile showed me this error:
Missing dependency 'class javax.annotation.Nullable'
Any ideas?
I found the answer in this issue on googlecode: http://code.google.com/p/guava-libraries/issues/detail?id=1095. To correct the problem in sbt you need to add this dependency:
"com.google.code.findbugs" % "jsr305" % "1.3.+"
The Scala compiler requires all annotation classes in the classpath. As this
class is not available in the classpath, the compilation fails.
In my particular case, the class is not used by the application. Hence, it is sufficient to disable the
fatal-warnings option in the build.
In my built.sbt I had the following line:
scalacOptions ++= Seq("-Yno-adapted-args", "-Ywarn-dead-code", "-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Xfatal-warnings")
I removed the "-Xfatal-warnings" and compilation was successful.

Build fails with Groovy 1.8, Hibernate JPA annotations

Build fails with Groovy 1.8, Hibernate JPA annotations
I've been stuck using Groovy 1.7.0 and unable to upgrade to the numerous updates due to a JPA Annotation build error.
My code is pretty standard JPA Annotations and has worked fine with the past groovy versions. I would like to be able to upgrade to Groovy 1.8.0. If anyone has seen and solved this issue, I will appreciate your help!
It seems to be failing to compile on the #JoinTable parts of all of my #ManyToMany annotations.
It fails with a "annotation value must be an annotation" message. I have looked through the JPA javadocs and I don't appear to be missing any required fields. My annotations worked fine in past versions.
Also, I'm using Gant for my build and I wouldn't rule that out as being a possible problem??
Here is an example mapping:
#ManyToMany(mappedBy='topics')
#JoinTable(name="screencast_topic",
joinColumns=[#JoinColumn(name="topicId")],
inverseJoinColumns=[#JoinColumn(name="screenCastId")])
#Sort(type=SortType.NATURAL)
Compile output:
[groovyc] Compiling 412 source files to /Users/ben/workspace/nofluff/build/webapps/ROOT/WEB-INF/classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] Abnormal termination of javac.
[groovyc] /var/folders/rs/rsmW8feBHJyH6EPl+V3XME+++TI/-Tmp-/groovy-generated-1581380806855929206-java-source/nfjs/model/Topic.java:84: <b>annotation value must be an annotation</b>
[groovyc] #org.apache.struts2.json.annotations.JSON(serialize=false) #javax.persistence.ManyToMany(mappedBy="topics") #javax.persistence.JoinTable(inverseJoinColumns={"org.codehaus.groovy.ast.AnnotationNode#7997f538"}, name="screencast_topic", joinColumns={"org.codehaus.groovy.ast.AnnotationNode#67646de5"}) #org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL) public java.util.SortedSet<nfjs.model.screencast.Screencast> getScreencasts() { return (java.util.SortedSet<nfjs.model.screencast.Screencast>)null;}
the groovy devs are aware of this issue (http://jira.codehaus.org/browse/GROOVY-4768).
Looks like a fix is in place for the next release. The current workaround is to make your own Groovy build and test it out.

Categories

Resources