What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?
Additional information:
I have seen this after copying a set of updated JAR files from a build on top of the existing JARs and restarting the application. The JARs are built using a Maven build process.
I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.
A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?
(rewritten 2015-07-28)
Summary: Eclipse had compiled some or all of the classes, and its compiler is more tolerant of errors.
Long explanation:
The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see, allowing the program to be run. This is possible as Eclipse uses its own built-in compiler, instead of javac from the JDK which Apache Maven uses, and which fails the compilation completely for errors. If you use Eclipse on a Maven project which you are also working with using the command line mvn command, this may happen.
The cure is to fix the errors and recompile, before running again.
The setting is marked with a red box in this screendump:
try to clean the eclipse project
you just try to clean maven by command
mvn clean
and after that following command
mvn eclipse:clean eclipse:eclipse
and rebuild your project....
Your compiled classes may need to be recompiled from the source with the new jars.
Try running "mvn clean" and then rebuild
The major part is correctly answered by Thorbjørn Ravn Andersen.
This answer tries to shed light on the remaining question: how could the class file with errors end up in the jar?
Each build (Maven & javac or Eclipse) signals in its specific way when it hits a compile error, and will refuse to create a Jar file from it (or at least prominently alert you). The most likely cause for silently getting class files with errors into a jar is by concurrent operation of Maven and Eclipse.
If you have Eclipse open while running a mvn build, you should disable Project > Build Automatically until mvn completes.
EDIT:
Let's try to split the riddle into three parts:
(1) What is the meaning of "java.lang.Error: Unresolved compilation
problem"
This has been explained by Thorbjørn Ravn Andersen. There is no doubt that Eclipse found an error at compile time.
(2) How can an eclipse-compiled class file end up in jar file created
by maven (assuming maven is not configured to used ecj for
compilation)?
This could happen either by invoking Maven with no or incomplete cleaning. Or, an automatic Eclipse build could react to changes in the filesystem (done by Maven) and re-compile a class, before Maven proceeds to collect class files into the jar (this is what I meant by "concurrent operation" in my original answer).
(3) How come there is a compile error, but mvn clean succeeds?
Again several possibilities: (a) compilers don't agree whether or not the source code is legal, or (b) Eclipse compiles with broken settings like incomplete classpath, wrong Java compliance etc. Either way a sequence of refresh and clean build in Eclipse should surface the problem.
I had this error when I used a launch configuration that had an invalid classpath. In my case, I had a project that initially used Maven and thus a launch configuration had a Maven classpath element in it. I had later changed the project to use Gradle and removed the Maven classpath from the project's classpath, but the launch configuration still used it. I got this error trying to run it. Cleaning and rebuilding the project did not resolve this error. Instead, edit the launch configuration, remove the project classpath element, then add the project back to the User Entries in the classpath.
I got this error multiple times and struggled to work out. Finally, I removed the run configuration and re-added the default entries. It worked beautifully.
Just try to include package name in eclipse in case if you forgot it
Import all packages before using it, EX: import java.util.Scanner before using Scanner class.
These improvements might work and it will not give Java: Unresolved compilation problem anymore.
Also make sure to check compiler compliance level and selected jdk version is same
As a weird case, I encountered such an exception where the exception message (unresolved compilation bla bla) was hardcoded inside of generated class' itself. Decompiling the class revealed this.
I had the same issue using the visual studio Code. The root cause was backup java file was left in the same directory.
Removed the backup java file
When the build failed, selected the Fix it, it cleaned up the cache and restarted the workSpace.
I've updated kotlin from 1.3.61 to 1.3.70 in my multiplatform project with android, jvm, ios and macosx64 targets not changing other code and whenever a gradle sync is attempted I get the following message (and the project build fails, of course):
CONFIGURE FAILED in 3s
Unable to find method 'org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.macosX64()Lorg/jetbrains/kotlin/gradle/plugin/mpp/KotlinNativeTargetWithHostTests;'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
I've tried the solutions described above, I also tried to clear .gradle/caches, but nothing changed. What might be the problem?
This happened because I had a buildSrc module where the dependencies' artifact names are declared like this:
object Deps {
object Android {
// artifacts
}
object Native {
// artifacts
}
// ...
}
and I had updated the kotlin dependency there, but I had forgotten to update the kotlin version in the build.gradle.kts of the buildSrc directory itself.
The Error:
Failed to sync Gradle project '-'
Error:Unable to find method 'org.gradle.internal.logging.progress.DefaultProgressLoggerFactory.(Lorg/gradle/internal/logging/progress/ProgressListener;Lorg/gradle/internal/time/TimeProvider;)V'.
You can see, a constructor inside a class, which is found in the logging jar (gradle_home/lib/grade-logging-version.jar) is missing.
So, I think the Class-Path does not contain this jar file.
Gradle Version: 3.5
Running using the Command Line works.
I have already tried this:
Gradle sync failed: Unable to find method
to-find-method, it does not work for me.
I have tried to use different versions.
I can't see any difference when enabling
"Use default gradle wrapper"
"Use gradle wrapper task configuration"
"Use local gradle distribution".
I had the exact same problem today.
The only way I was able to get it to work was to remove my IntelliJ IDEA IDE, get the latest from the website (with JDK) and put it in a new folder (i.e. no overwriting existing files).
After that, I deleted the .idea folder from the project and reimported it cleanly into the "new" IntelliJ.
I suspect upgrading IntelliJ from Version <= 2016.x caused the issue, since a new installation / clean extraction from archive caused it to work on the fly.
IntelliJ downloaded the dependencies listed in my build.gradle file and they show up in the External Library, but IntelliJ fails to find them during compile. It just throws a bunch of "package x does not exist" and "cannot resolve symbol". Under the Project Structure -> Modules -> Dependencies they all show up and are listed as compile.
If I try to build it with Gradle it's successful, so it's just IntelliJ. Any ideas?
If it's important, I'm using this on a Mac.
Found the answer. IntelliJ was treating Main and Test as modules with no dependency related to the project itself and all of the library dependencies were stored at the project level.
I killed off Main and Test as modules and it sorted itself out.
We are trying to setup a number of Gradle (v1.5) web projects in IntelliJ v12.1.2
The new JetGradle integration works fine until we get the the Artifacts
The module is imported as a Gradle project, the artifact is been created as a Web Application (Exploded) and the Web facet has been added - all the dependencies that are declared in the build.gradle file are correctly added to the WEB-INF/lib directory in the artifact
The problem comes when we make a change to the dependencies in the build.gradle file and refresh the module using the JetGradle refresh button - the dependencies of the module are updated correctly but nothing is changed in the artifact
If we changing just one dependency then the change can be done manually but if there are a number of changes or there are a lot of new/changed transative dependencies then it seems the only timely way to get the correct dependencies in the artifact is to delete and recreate it
Am I missing something obvious, does anyone know a better way to update the artifacts
Thanks
Automatic artifact config update is not implemented yet. I've created corresponding ticket for that - http://youtrack.jetbrains.com/issue/IDEA-109369