lombok-intellij-plugin: Library does not match the bytecode for class XXX
Short description
When using libraries built with lombok and attaching source with lombok annotations, IntelliJ complains about mismatch between source and class file.
Expected behavior
IntelliJ should not complain about mismatch since the source, when lombok-ed, will compile to the provided class.
Version information
- IDEA Version: IntelliJ IDEA 2017.3.2 (Community Edition) Build #IC-173.4127.27, built on December 25, 2017 JRE: 1.8.0_152-release-1024-b8 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.10.0-42-generic
- JDK Version: 1.8.0_111
- OS Type & Version: Ubuntu 16.04 LTS
- Lombok Plugin Version: 0.15.17.2
- Lombok Dependency Version: 1.16.6
Steps to reproduce
- In a source root run the following
mvn archetype:generate -DgroupId=com.test.rb.m1 -DartifactId=module1 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
mvn archetype:generate -DgroupId=com.test.rb.m2 -DartifactId=module2 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
- update module 1 pom.xml: 2.1 add lombok dependency
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
2.2 add source plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- update module 1 App.java:
@Setter
@Getter
public class App {
private String myField;
@SneakyThrows
public void ex() {
throw new Exception("ex");
}
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
- update module 2 pom.xml - add dependency on module 1:
<dependency>
<groupId>com.test.rb.m1</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
- run “mvn install” on module 1
- open module 2 in IntelliJ, open class “com.test.rb.m1.App”
IntelliJ shows a red error “Library source does not match the bytecode for class App”
Sample project
Please provide a sample project that exhibits the problem.
See lombok_bug.tar.gz](https://github.com/mplushnikov/lombok-intellij-plugin/files/1620326/lombok_bug.tar.gz)
You should also include .idea folder so we can inspect the settings.
- [X ] Sample project provided - [
- [X ] I am able to reproduce this error on the sample project by following the steps described above
Additional information
no
Stacktrace
none
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 40
- Comments: 15
@mplushnikov Any updates on this?
Any update on this?
@alexejk The fact that you are not having this issue when using Lombok Plugin probably is because of you don’t download the source files for the jars, the bytecode has the whole code that Lombok generated, so no errors show. But normally, we’re more likely interested in source files, you know the bytecode is really not for reading. Maybe, this IntelliJ plugin can adopt the feature that combining the source and bytecode, so we can achieve that:
THX
I’ve done a work a round that helped me to solve this problem. Using this plugin (https://plugins.gradle.org/plugin/io.freefair.lombok) what I do is to
delombokmy files and use them to create the source. It’s not the best solution but at least now the source is pure Java and it can be debugged.build.gradle
This is the issue that you will have with Lombok itself and not this plugin specifically. Bytecode generated with lombok is going to differ from what you see in sources - thats the nature of Project Lombok.
You can generate sources explicitly with delombok step if you want and package it - but I’m not entirely sure what are you expecting this IntelliJ plugin to do.
FYI, at my workplace we are not having this issue when using Lombok Plugin for all developers in their IDE even if libraries are built with lombok - so I believe it’s mainly an issue on the setup/user side or an issue of not understanding how things work behind the scenes.
Yes this is sorely needed - we built all our reusable libraries with Lombok, only to discover that users have a hard time using them in their projects, since the library source code is not synchronized; it makes debugging that much harder…