Add Lombok to a Gradle project in Intellij - java

New to Gradle. I Apologize if this is a bad question.
I've been trying to start a plain Java8 Gradle project. Everything was great until I tried to add Lombok to my project.
My Intellij IDE has all the settings required for Lombok.
Lombok plugin installed and activated
Annotation processor is on
The IDE is handling the annotations perfectly. No errors showing, and the boilerplate is shown in the code structure.
However, when I try to build the project or run the main method using Intellij, the compiler complains that the boilerplate Lombok is supposed to generate doesn't exist.
Environment
186590cf4989:JokerJava$ gradlew --version
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.5 (Oracle Corporation 11.0.5+10-LTS)
OS: Mac OS X 10.14.6 x86_64
Some error message below:
8:23:21 PM: Executing task 'build'...
> Task :generateLombokConfig UP-TO-DATE
> Task :compileJava FAILED
2 actionable tasks: 1 executed, 1 up-to-date
warning: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.gradle.api.internal.tasks.compile.processing.IncrementalProcessingEnvironment
Lombok supports: sun/apple javac 1.6, ECJ
workspace/tank/JokerJava/src/main/java/tictactoe/game/gui/TicTacToeButton.java:11: error: variable index not initialized in the default constructor
private final int index;
^
workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:42: error: constructor TicTacToeButton in class TicTacToeButton cannot be applied to given types;
buttons[i] = new TicTacToeButton(i);
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:70: error: cannot find symbol
int index = buttonClicked.getIndex();
^
symbol: method getIndex()
location: variable buttonClicked of type TicTacToeButton
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:86: error: cannot find symbol
update(opponentAction.getPlayer(), opponentAction.getIndex());
^
symbol: method getPlayer()
location: variable opponentAction of type UserAction
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:86: error: cannot find symbol
update(opponentAction.getPlayer(), opponentAction.getIndex());
^
symbol: method getIndex()
location: variable opponentAction of type UserAction
Note: /workspace/tank/JokerJava/src/main/java/Client.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors
1 warning
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
8:23:22 PM: Task execution finished 'build'.
See below for my build.gradle config
plugins {
id 'java'
id "io.freefair.lombok" version "5.0.0-rc2"
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}

Even if you don't want to use spring, head over to the spring Initializer at https://start.spring.io/ and choose Gradle and add the Lombok dependency. It'll create a build.gradle for you with Lombok in the appropriate configurations (including annotationProcessor)

Related

Gradle build fails java.security.NoSuchAlgorithmException: Error constructing implementation on raspberry running Ubuntu 20.04

I am trying to build an empty gradle application with the following build.gradle file.
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.json', name: 'json', version: '20220924'
implementation group: 'uk.co.caprica', name: 'vlcj', version: '4.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
When I try to build I get the following error:
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve org.json:json:20220924.
Required by:
project :
> Could not resolve org.json:json:20220924.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/json/json/20220924/json-20220924.pom'.
> java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
> Could not resolve uk.co.caprica:vlcj:4.8.1.
Required by:
project :
> Could not resolve uk.co.caprica:vlcj:4.8.1.
> Could not get resource 'https://repo.maven.apache.org/maven2/uk/co/caprica/vlcj/4.8.1/vlcj-4.8.1.pom'.
> java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
1 actionable task: 1 executed
What I tried so far with no success:
add maven certificate to jvm cacerts
What I am using
gradle 7.4
jdk and jre 11
ubuntu 20.04 (raspberry aarch64)
The maven repo exists and I am a bit hopeless what should I do. Any suggestions?
Thanks in advance if you can help!
UPDATE:
As #dave_thompson_085 recommended, I ran the build with stacktrace and got the following error:
java.security.KeyManagementException: problem accessing trust store
Tried to reinstall java but the same problem exist.
If anyone runs into the same problem as me just set the variable for
javax.net.ssl.trustStore
to where your cacerts are located.
For me it was: /usr/lib/jvm/java-11-openjdk-arm64/lib/security/cacerts
If you don't want to add this parameter every time when you are trying to build here is a solid solution for that.

Environment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module

I want to using GraalVM in my Spring Boot 2.3.10.RELEASE project because it can decrease the memory usage of JVM(Now I am using JDK 11), so I add the dependencies:
api "org.springframework.experimental:spring-native:0.10.2"
add the gradle plugin:
apply plugin: "com.github.ayltai.spring-graalvm-native-plugin"
add native build config:
nativeImage {
mainClassName = 'com.dolphin.soa.manage.AppStarter'
traceClassInitialization = true
reportExceptionStackTraces = true
removeUnusedAutoConfig = true
removeYamlSupport = true
removeSpelSupport = true
removeJmxSupport = true
maxHeapSize = '4G'
}
finnaly I am using this Gradle(7.0) command to build a native jar:
./gradlew clean :dolphin-manage:dolphin-manage-service:bootBuildImage -x test
but show this error:
> Configure project :dolphin-acientbay
/Users/dolphin/source/retire
> Configure project :dolphin-post
/Users/dolphin/source/retire
> Configure project :dolphin-template
/Users/dolphin/source/retire
> Task :dolphin-common:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':dolphin-common:compileJava'.
> java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module #0x2155f75f) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module #0x2155f75f
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6m 49s
5 actionable tasks: 1 executed, 4 up-to-date
(base)
is it a compatible problem about GraalVM and lombok? is it possible to fix it?
I'm seeing this same type of error running spotless on my Java project. I just reported a bug about this to them: https://github.com/diffplug/spotless/issues/1244
I diagnosed the problem as some kind behavioral change between Java 15 and Java 16. So one thing you can do is revert to an earlier version of Java to see if that makes the issue go away. If it does, you should report a bug similar to what I did to the project with the problem so they can try to fix it.

Problem with Gradle build when trying to run vertx application

´´´
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'io.vertx.vertx-plugin' version '1.2.0'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
compile 'io.vertx:vertx-web-client:4.0.2'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:29.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.13'
}
vertx {
mainVerticle = 'Reactx.BackendVerticle'
}
//Backend Verticle.java
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package Reactx;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
public class BackendVerticle extends AbstractVerticle {
#Override
public void start() {
// Create an HTTP server which simply returns "Hello World!" to each request.
// If a configuration is set it get the specified name
Router router = Router.router(vertx);
Route messageRoute = router.get("/api/message"); // (1)
messageRoute.handler(rc -> {
rc.response().end("Hello React from Vert.x!"); // (2)
});
router.get().handler(StaticHandler.create()); // (3)
vertx.createHttpServer()
.requestHandler(router)
.listen(8080);
}
// tag::main[]
public static void main(String[] args) {
Vertx vertx = Vertx.vertx(); // <1>
vertx.deployVerticle(new BackendVerticle()); // <2>
}
// end::main[]
}
´´´
When I try to do gradle run, I am getting an error::compileJava Task failed.
How can this be solved? I cannot try kotlin because I have some dependency and I want to execute this only in gradle.build. I am using gradle version 6.6 which is also due to the dependency of project.
Adding failure stacktrace:
Gradle Version: 6.6
Java Home: C:\...\jdk1.8.0_282
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: run
> Task :compileJava FAILED
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:8: error: package io.vertx.ext.web does not exist
import io.vertx.ext.web.Route;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:9: error: package io.vertx.ext.web does not exist
import io.vertx.ext.web.Router;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:10: error: package io.vertx.ext.web.handler does not exist
import io.vertx.ext.web.handler.StaticHandler;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:18: error: cannot find symbol
Router router = Router.router(vertx);
^
symbol: class Router
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:18: error: cannot find symbol
Router router = Router.router(vertx);
^
symbol: variable Router
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:19: error: cannot find symbol
Route messageRoute = router.get("/api/message"); // (1)
^
symbol: class Route
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:24: error: cannot find symbol
router.get().handler(StaticHandler.create()); // (3)
^
symbol: variable StaticHandler
location: class BackendVerticle
7 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.6/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 253ms
1 actionable task: 1 executed
You are missing the vertx-web as a dependency.
To fix the compilation issues you need to add:
dependencies {
//...
compile 'io.vertx:vertx-web:4.0.2'
}

How to fix ionic ImageFetcher.java:293 error for Android Build?

When I run ionic cordova run android --device I get the following error:
lint finished in 2.68 s
/Users/me/Sites/my_app/platforms/android/app/src/main/java/com/synconset/ImageFetcher.java:293: error: Entry is not public in LinkedHashMap; cannot be accessed from outside package
protected boolean removeEldestEntry(LinkedHashMap.Entry<Integer, Bitmap> eldest) {
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
BUILD FAILED in 1s
27 actionable tasks: 1 executed, 26 up-to-date
/Users/me/Sites/my_app/platforms/android/gradlew: Command failed with exit code 1 Error output:
/Users/me/Sites/my_app/platforms/android/app/src/main/java/com/synconset/ImageFetcher.java:293: error: Entry is not public in LinkedHashMap; cannot be accessed from outside package
protected boolean removeEldestEntry(LinkedHashMap.Entry<Integer, Bitmap> eldest) {
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Here is my Android build.gradle
buildscript {
repositories {
maven {
url "https://maven.google.com"
}
jcenter()
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
jcenter()
}
//This replaces project.properties w.r.t. build settings
project.ext {
defaultBuildToolsVersion="27.0.1" //String
defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
defaultTargetSdkVersion=27 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=27 //Integer - We ALWAYS compile with the latest by default
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here things I have done:
I changed the defaultCompileSdkVersion from 27 to 28 same result.
I added
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
at the bottom of the build.gradle same.
I removed the build and re-install it, same error.
I am out of option.
Thank you for your help in advance.
My Gradle version:
Gradle 4.10.2
Build time: 2018-09-19 18:10:15 UTC
Revision: b4d8d5d170bb4ba516e88d7fe5647e2323d791dd
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_25 (Oracle Corporation 25.25-b02)
OS: Mac OS X 10.14.1 x86_64

Cascading examples failed to compile?

In shell I typed gradle cleanJar in the Impatient/part1 directory. The output is below. The error is "class file for org.apache.hadoop.mapred.JobConf not found". Why did it fail to compile?
:clean UP-TO-DATE
:compileJava
Download http://conjars.org/repo/cascading/cascading-core/2.0.1/cascading-core-2.0.1.pom
Download http://conjars.org/repo/cascading/cascading-hadoop/2.0.1/cascading-hadoop-2.0.1.pom
Download http://conjars.org/repo/riffle/riffle/0.1-dev/riffle-0.1-dev.pom
Download http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.pom
Download http://repo1.maven.org/maven2/org/slf4j/slf4j-parent/1.6.1/slf4j-parent-1.6.1.pom
Download http://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.pom
Download http://conjars.org/repo/thirdparty/jgrapht-jdk1.6/0.8.1/jgrapht-jdk1.6-0.8.1.pom
Download http://repo1.maven.org/maven2/org/codehaus/janino/janino/2.5.16/janino-2.5.16.pom
Download http://conjars.org/repo/cascading/cascading-core/2.0.1/cascading-core-2.0.1.jar
Download http://conjars.org/repo/cascading/cascading-hadoop/2.0.1/cascading-hadoop-2.0.1.jar
Download http://conjars.org/repo/riffle/riffle/0.1-dev/riffle-0.1-dev.jar
Download http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar
Download http://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar
Download http://conjars.org/repo/thirdparty/jgrapht-jdk1.6/0.8.1/jgrapht-jdk1.6-0.8.1.jar
Download http://repo1.maven.org/maven2/org/codehaus/janino/janino/2.5.16/janino-2.5.16.jar
/home/is_admin/lab/cascading/Impatient/part1/src/main/java/impatient/Main.java:50: error: cannot access JobConf
Tap inTap = new Hfs( new TextDelimited( true, "\t" ), inPath );
^
class file for org.apache.hadoop.mapred.JobConf not found
1 error
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 22.599 secs
try using Java 6 , gradle has some known issues with java 7
Add hadoop-core-1.x.y.jar from hadoop distribution to path.
This worked for me in CoPA example. I added to eclipse build path.
Add this to gradle dependencies{} section
compile( group: 'org.apache.hadoop', name: 'hadoop-core', version: '1.2.0' )
It seems like class not found, please check libraries in build path entries.
I had the same issue today trying the Cascading for the Impatient tutorial. I have solved adding the following to my build.gradle in the dependenciessection :
compile 'org.apache.hadoop:hadoop-client:2.3.0'
I wanted to use Hadoop 2.3.0, but I guess that you can choose your own version of Hadoop.
PS : In order to use the first hadoop-mapred package, you have to add the following instead :
compile 'org.apache.hadoop:hadoop-mapred:0.22.0'
You can find all the repos you might need for Hadoop here.
Thanks Lalit,
Adding the below line did the trick for me without have to change any java version..
compile( group: 'org.apache.hadoop', name: 'hadoop-core', version: '1.2.0' )
Alternatively, I can even add the hadoop-core jar in the class path and mention that in the gradle path

Categories