I was about building a gradle 5 project in IDEA.
The lombok dependency was set to compileOnly in the build.gradle file and running it resulted in success from command line and IDEA gradle tool as well.
"Funny" fact, that lombok isn't included in Source Sets, so my lombok imports are failing....
I googled for it, and in theory since IDEA 2017.2 + Gradle 4 it's a fixed issue, IDEA should pick up compileOnly dependencies as well.
In the reality, it does not work.
Any Gradle plugin, or idea to solve this issue? :)
Thanks.
ui.:
VERSION 1
Using compileOnly & annotationProcessor both for prod code and tests resulted in
from command-line, gradle is able to run everything with SUCCESS
from IDEA, it's impossible, imports are failing with lombok
VERSION 2
Using compile & annotationProcessor
from command-line, gradle is able to run everything with SUCCESS
from IDEA, imports are OK, everything is fine
dependencies {...compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")...}
According to https://projectlombok.org/setup/gradle
you need to write in your build.gradle
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.6'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
}
It works for me
You can upgrade the IDEA version to 2019.1 or use the 4.x version of Gradle.
Related
I'm following this example https://github.com/vert-x3/vertx-examples/tree/master/web-api-service-example. Instead of using Java and Maven I'm trying to do it in Kotlin and Gradle. When I run the project I get a Cannot find proxyClass: error. My build.gradle file has this
annotationProcessor "io.vertx:vertx-codegen:$vertxVersion:processor"
annotationProcessor "io.vertx:vertx-web-api-service:$vertxVersion"
compileOnly "io.vertx:vertx-codegen:$vertxVersion"
compile "io.vertx:vertx-web-api-service:$vertxVersion"`
I can build successfully with Gradle
I want to add a dependency to Gradle project that is visible to the annotation processor during the processing.
But at the same time I do not want this dependency to be accessible from the source code.
How can this be done?
If you are using a recent version of Gradle, then annotation processor dependencies are declared in a separate configuration annotationProcessor that is only resolved for that purpose.
Versions prior to 4.6 used to find them from the compile classpath, and if you have to use old versions, I don't think there is much you can do.
Example for 4.6+:
dependencies {
annotationProcessor 'com.google.dagger:dagger-compiler:2.8'
}
If your annotation processor requires any other dependencies for compiling your source code, you have no choice but to add them to the compile classpath, which will make them visible in an IDE. But you can use the compileOnly configuration to limit the scope so they won't be visible at runtime or selected as a transitive dependency. Example:
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}
In a project that uses the javax.script scripting support added in 1.1 in its unit tests, upgrading the Kotlin language version from 1.3.21 to 1.3.30 caused those tests to fail with the following exception:
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingCompilerConfigurationComponentRegistrar
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.makeCompilerConfiguration(KotlinJsr223JvmLocalScriptEngine.kt:72)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.access$makeCompilerConfiguration(KotlinJsr223JvmLocalScriptEngine.kt:38)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:49)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:38)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplCompiler(KotlinJsr223JvmLocalScriptEngine.kt)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:53)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:38)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getLocalEvaluator(KotlinJsr223JvmLocalScriptEngine.kt)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplEvaluator(KotlinJsr223JvmLocalScriptEngine.kt:55)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.createState(KotlinJsr223JvmLocalScriptEngine.kt:59)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.createState$default(KotlinJsr223JvmScriptEngineBase.kt:46)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.getCurrentState(KotlinJsr223JvmScriptEngineBase.kt:53)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.nextCodeLine(KotlinJsr223JvmScriptEngineBase.kt:44)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compileAndEval(KotlinJsr223JvmScriptEngineBase.kt:59)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:31)
The relevant lines in build.gradle are:
dependencies {
// ... other stuff ...
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}
where ext.kotlin_version is either "1.3.21" or "1.3.30".
Why did this break, and how can I fix it?
It broke because JetBrains have refactored the scripting functionality into a plugin, and the dependencies required to successfully run Kotlin script through JSR223 have changed.
The relevant issue on the Kotlin bug tracker is KT-30972, which was closed as a duplicate of KT-30986.
The upshot is, you need to adjust the dependencies to include kotlin-scripting-compiler-embeddable.
dependencies {
// ... other stuff ...
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}
the working version nowadays is simply:
dependencies {
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223:${Deps.JetBrains.Kotlin.VERSION}")
}
which pulls in all necessary dependencies transitively.
Also the META-INF/services/javax.script.ScriptEngineFactory File seems not to be necessary if doing so.
Following is my build.gradle file. My project compiles locally (IntelliJ-IDEA is my IDE), but when I push it to GitHub, the travis-ci build fails. My gradle version is gradle-5.2.
apply plugin: "java"
apply plugin: 'jacoco'
sourceCompatibility = 1.8
version = "1.0"
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.2'
compileOnly 'org.projectlombok:lombok:1.18.2'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.2'
testCompileOnly 'org.projectlombok:lombok:1.18.2'
}
FAILURE: Build failed with an exception.
Where: Build file '/home/travis/build/XXX/PROJECT/build.gradle' line: 33
What went wrong: A problem occurred evaluating root project 'PROJECT'.
Could not find method annotationProcessor() for arguments [org.projectlombok:lombok:1.18.2] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
The annotationProcessor in build.gradle seems not to be parsed, I'm not sure what the underlying issue is. Any help would be appreciated. Thanks.
As #M.Ricciuti said, the annotationProcessor is available from gradle versions 4.6 and later. So what we should do is just confirm that gradle's version >= 4.6. We'd be better off using the Wrapper.Thanks, that's all.
A ery easy way to update the gradle version of your project in intellij is to go to inside your project, gradle, wrapper, gradle-wrapper.properties and update the version in the line below:
disributionUrl=https://services.gradle.org/distributions/gradle-4.6-bin.zip
I am getting a weird issue in IntelliJ. I am using Lombok (1.18.2), IntelliJ(2018.2.2) and JUnit 5 in gradle 4 multi-module project.
It took me hours to replicate this.
Run all test case with coverage.
Following a pop up will come
if I press OK and re-run the unit test case. It will start failing with java.lang.NoSuchMethodError for the getters and setters.
removing Lombok and generating getter and setter after this has no effect as well.
Tried everything to fix this (enable annotation processor, Lombok plugin, clean build) but no luck.
EDIT 1:
Root build.gradle:
implementation 'org.projectlombok:lombok:1.18.2'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.3.1')
testImplementation('org.junit.jupiter:junit-jupiter-params:5.3.1')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.1')
testImplementation("org.junit.platform:junit-platform-launcher:1.3.1")
testImplementation("org.junit.vintage:junit-vintage-engine:5.3.1")
testImplementation "org.mockito:mockito-core:2.+"
testImplementation('org.mockito:mockito-junit-jupiter:2.22.0')
sub-project build.gradle
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
I solved this issue by making following changes:
Enable annotation processing in Intellij.(File | Settings | Build, Execution, Deployment | Compiler | Annotation Processors)
select processor path and point to lombok-1.18.4.jar because I just want to enable it for Lombok and not for Mapstruct. If enabled for both then it generates the Mapstruct classes in default location.
under File "Invalidate cache and restart"
under Build option "Rebuild project"
This will solve it. It took me a while to make it working in Intellij.