108

No idea what's wrong here.. I removed all files I had from the local maven repository and let it download everything from scratch but I can't get rid of this error:

enter image description here

Why am I seeing this and how can I get rid of it?


[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ wordvectors ---
[INFO] masterthesis.code:wordvectors:jar:1.0-SNAPSHOT
[INFO] +- org.apache.spark:spark-core_2.10:jar:1.6.0:compile
[INFO] |  \- org.apache.hadoop:hadoop-client:jar:2.2.0:compile
[INFO] |     \- org.apache.hadoop:hadoop-common:jar:2.2.0:compile
[INFO] |        \- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |           \- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for conflict with 20040616)
[INFO] \- org.deeplearning4j:deeplearning4j-ui:jar:0.4-rc3.8:compile
[INFO]    \- org.deeplearning4j:deeplearning4j-nlp:jar:0.4-rc3.8:compile
[INFO]       \- it.unimi.dsi:dsiutils:jar:2.2.2:compile
[INFO]          \- commons-collections:commons-collections:jar:20040616:compile
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • 1
    You might have a dependency with a transitive dependency on a different version of the same library. You can spot them following the example at https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html. If you find that there is a mismatch, you can tell your dependency's transitive dependency to be excluded so that everyone uses the same lib version. – Hank D Apr 20 '16 at 22:34
  • @HankD How can I tell which one of those are transitive? I added the dependency try but it does not seem that I have a transitive one included here. – Stefan Falk Apr 23 '16 at 15:51
  • The transitive ones are the ones starting with `\-` so I don't think that's it. You might try running `mvn dependency:sources` to force an update of the source code (see http://stackoverflow.com/questions/2059431/get-source-jars-from-maven-repository) – Hank D Apr 23 '16 at 23:26

20 Answers20

50

There's nothing wrong with IDEA, nor your dependencies or local maven caches, it's correctly identifying the mismatch.

Here's how to check:

  • Open class in question
  • Click "Show diff"
  • Choose "Ignore whitespaces and empty lines"

diff screenshot

You can clearly see (ignoring JavaDoc and FQCNs) that the class file has extra checks included for the @NonNull annotated arguments. The import says lombok.NonNull, and the documentation shows this transformation will happen.

I guess the best course of action is either to ignore this warning or ask the project's maintainers to build the sources.jar from the lombok-processed source code if that's possible. I think they'll need to employ delomboking and this Maven plugin, but never built lombok code myself.

TWiStErRob
  • 44,762
  • 26
  • 170
  • 254
  • 1
    How do I disable this warning from appearing? It steals focus from the editor window and I am forced to use mouse to bring focus back. Really annoying since it happens quite a lot for me... and is never actionable. – Sergiy Belozorov Sep 04 '19 at 14:16
  • 1
    @SergiyBelozorov I don't think there's a built-in way, but it may be possible to write a plugin that removes the feature by disabling the extension point (if that's possible). See https://github.com/JetBrains/intellij-community/search?q=LibrarySourceNotificationProvider. I recommend you ask a question at https://intellij-support.jetbrains.com/hc/en-us/community/topics/200366979-IntelliJ-IDEA-Open-API-and-Plugin-Development or open a bug at https://youtrack.jetbrains.com/issues/IDEA for stealing focus. – TWiStErRob Sep 04 '19 at 14:44
  • This seems like a wrong answer - in my case i had to take action and delete a dependency – Ohad Bitton Mar 07 '22 at 15:05
  • 1
    can we all stop using lombok, getters aren't that hard to write – jvans Mar 01 '23 at 23:22
48

Had same problem - did a gradlew clean from the command line, then went into Android Studio and did a File -> Invalidate Caches and Restart and all was well again..

LanDenLabs
  • 1,566
  • 16
  • 10
19

In solving this, I had no need to mess around with Maven, and dealt with IntelliJ IDEA alone.

For me this problem arose out of confusion between three concepts in the IntelliJ IDEA: modules, libraries and dependencies. I had different projects, using different packages, some of which were referring to each other in inconsistent ways. I was also being inconsistent about how to refer to downloaded third-party packages.

It was easy once I distinguished the three concepts of modules, libraries and dependencies. How I clarified them in my mind:

1) Libraries refer to code (compiled or not) which is not going to change.

2) Modules refer to parts of the project (yours if you are working alone) where the code is subject to change.

3) A dependency (for this conversation) is a library or other module which a particular module will use.

I got the error from adding the code of an ongoing project, which was originally created by another IDE, as a dependency in the IntelliJ IDEA. In theory this should work, and it does, but like you I can't ignore a big red banner across the top of my development environment!

To solve the problem:

Modules Open File>Project Structure>Modules, and using the top left green plus sign (not the one to the right) added other projects where the code is likely to change. This makes them 'alive' to IntelliJ, and not a dusty old immutable library which, if changed, might cause the alarm banner to shout at you. At this stage, only use the big panel taking up most of the dialog for checking the imported jars, source code, etc., to verify what you want has arrived.

Adding a module

Libraries Open File>Project Structure>Libraries, and again using the top left green plus sign add the folder containing the code that will not change. The other green plus sign to the right allows you to add internal folders to an already added library, but IntelliJ is good at finding these in different project structures, so consider starting from scratch adding a new library, rather than adding specific folders that you think are missing and causing multiple copies to exist, another thing which causes confusion (understandably) to IntelliJ.

Adding a library

Dependencies Now everything should be ready for you to return to File>Project Structure>Modules. This time go to the large panel taking up most of the dialog and change to the 'Dependencies' tab. My preferred way of working at this stage (particularly when the project is large and complex) is to work my way down the listed modules, adding the libraries and module dependencies for each module as I go. This time for each module use the green plus sign to the right to add each library or module that you need, and these should be offered to you from the ones added in the last step.

enter image description here

WARNING There are two important steps which you should be careful of when finishing the process:

1. Make sure that each dependency you added for each module has scope 'Compile' in the dependencies tab.

2. When you are finished, click the Apply button at the bottom of the Project Structures dialog before clicking OK. It seems like it should be automatic, like so much else in IntelliJ, but I do not think it is. I have lost changes I have made to the Project Structure by not clicking Apply before exiting the dialog.

Ger
  • 889
  • 1
  • 12
  • 21
3

The following worked in my case:

  1. Locate the dependency in the project structure.
  2. Right click on the dependency and Open Library settings.
  3. Right click and delete the dependency.
  4. Re-import all dependencies again.
user97213
  • 31
  • 1
  • 3
1

I had this problem and to my knowledge, I know two solutions to solve this:

  1. click "build" on top of your IntellIj windows, then "Build project"

and/or

  1. on the right side, you click on "maeven projects"(vertically written in small), then "clean"
Dmitriy
  • 5,525
  • 12
  • 25
  • 38
Charles Julien
  • 365
  • 3
  • 16
  • 1
    Except here the issue was specifically around Lombok, which performs bytecode modifications based on annotations, so the source will never align with the Lombok-ized class files. – Dave Newton Sep 13 '18 at 14:16
  • @DaveNewton Were you able to find the solution? I too am facing the same and it has to do with the Lombok – Abhishek Raj Sep 14 '18 at 07:20
1

Just now I had this problem,

What helped me:

I've found .ideaLibSources folder, by selecting 'Copy path' in context menu after right-clicking on jar file (You could find jar-file link in upper region of idea, when file is opened in editor and it is in focus) then just removed unwonted-sources.jar from this folder. aaand redownload.

btw invalidate/restart didn't help

1

Check for multiple sources attached to lib

It could be due to multiple sources defined in Libraries. Check and remove multiple sources under File > Project Structure > Libraries > lib with issue > Sources

e.g. File > Project Structure > Libraries > Maven: com.rohit:example:1.0.0 > Sources --> remove multiple sources

1

Here's what I did :

  1. Invalidate caches and restart.
  2. Rebuild the project (Build->Rebuild).
  3. Rebuild with your build system (ex. mvn clean install).

Worked for me.

1

There is another reason. This class depends on other libraries, but the dependency is not managed by maven. Try to add this dependency in your Maven pom.xml.

nilknow
  • 319
  • 3
  • 6
0

In my case helped the next steps:

  1. remove the library from local repository
  2. rebuild the project
IKo
  • 4,998
  • 8
  • 34
  • 54
0

It is caused by old-compiled version of the package that relies in .m2/repository.

 All you need to do is
  -> Find the package in m2 folder and delete it
  -> Rebuild the required package or re-download from the repository
  -> Reimport all packages in the project
Mukundhan
  • 3,284
  • 23
  • 36
0

I had this problem after migrating an oldish app to Androidx. The issue turned out to be a problem with the ActionBar using an AppTheme style not compatible with Androidx. This was not picked up by the debugger. I fixed the issue by

  1. changing the AppTheme setting in the res/values/styles.xml file to:

<style name="AppBaseTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> 
</style>
  1. followed by gradlew clean
BillC
  • 145
  • 2
  • 8
0

In my case I got a secondary pom.xml in my project used for backup (pom.xml.versionBackup) which was causing this "Library source does not match the bytecode for class" nightmare. Nothing else worked (clean library cache, remote the .idea folder, remove the ~/.m2 folder, remove the *.iml files, remote the target folders, ...)

0

Usually invalidate caches & "gradle clean build" works but this time it didn't for some reason. After trying all the answers I decided just to close the project window, delete the .idea folder in the project folder, and open again the project with IntelliJ (it recreates the .idea folder once opening it as project). Worked flawlessly.

Gad Wissberg
  • 455
  • 1
  • 6
  • 19
0

This can happen when the library maintainer

  • obfuscates the jar with e.g. proguard, e.g. to reduce the jar size
  • but also publishes the source which is not obfuscated and, thus, differs from the byte code

You could build the jar yourself without obfuscation and use this as dependency.

  • checkout the source code from github if the project is open source
  • comment out the obfuscation tasks in the build.gradle file
  • publish the jar to your local repository gradle publishToMavenLocal
  • add mavenLocal() to the beginning of the repositories section of your project's build.gradle
  • reference this jar version from your own project and rebuild your project
hb0
  • 3,350
  • 3
  • 30
  • 48
0

This happened to me while using a dependency management (azure bom) - the bom has a different version than what i explicitly have in the pom - resolution was to delete the other dependency and rely on the dependencies from the bom.

Ohad Bitton
  • 460
  • 2
  • 14
0

In my case, I had a multi-module project, where I was getting errors that certain classes were undefined. So I located a jar file that contained the definitions to those classes. To get rid of the errors, I added the jar file as a library to Files > Project Structure > Project Settings > Modules > Dependencies, to EVERY child module in the project. This worked for awhile, and allowed me to build succesfully.

However, after some time passed, I needed to update some classes, but I kept getting the "Library source does not match the bytecode for class" error for some files, which made it unlikely that I could edit them. I got it when I opened a file that was cross-defined in the jar libary I added. So, to avoid having .class and .java files conflicted, I started over by removing the jar library from ALL child modules, and instead focusing on adding it to a select few of the child modules that made sense.

Also, I moved the libary jar file to the bottom of the dependencies window, so that anything that was cross-defined in a module would take precedence over the jar library, but anything not defined in the module would be defined by the library jar. I did a rebuild (ide rebuild, not maven) and it cleared up the "Library source does not match the bytecode for class" statement.

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
Steve T
  • 165
  • 11
0

I had that problem because Maven home path was pointing to an old Maven version.

  1. enter new path at Settings> Build, Execution, Deployment > Build Tools > Maven > ...

  2. run mvn clean install -U

enter image description here

enter image description here

Cohensius
  • 385
  • 7
  • 18
0

I had the same issue but in my case i have changed the library version and it was not updated in pom.xml of project.

kamboj
  • 411
  • 1
  • 9
  • 18
-1

I just copied the contents of the file and deleted it. Later I just created a new file with same name as the older one and pasted the code in it. It worked for me.

For me just recreating the file has worked.

Bharat
  • 1,044
  • 15
  • 34