spring-attic / spring-ide

Spring Development Environment for Eclipse
299 stars 125 forks source link

Unable to make STS work with annotation processors & gradle #273

Open thekalinga opened 6 years ago

thekalinga commented 6 years ago

I created a sample project that integrated lombok + mapstruct + gradle + STS (with buildship plugin). The sample project is located at https://github.com/thekalinga/gradle-apt-plugin-eclipse-issue

But, STS does not generate classes using mapstruct despite the annotation processor being available in the dependencies & exposed via facory paths. I'm unable to figure out what could be causing this issue

Would appreciate if you could help me decide whether the issue is with the plugin/something I did (or) did not do/with IDE

Here are the steps I followed

Imported the project into STS using Gradle -> Existing Gradle Project, I ran ./gradlew eclipseJdtApt eclipseFactorypath from terminal & refreshed the project in eclipse. Then I tried cleaning & rebuilding the project. No files are being generated under .apt_generated

I see proper values set w.r.t project properties. Here are the screenshots of the settings

  1. Properties -> Java Compiler java compiler settings
  2. Properties -> Java Compiler -> Annotation Processing annotation processing
  3. Properties -> Java Compiler -> Annotation Processing -> Factory Path factory path

I'm using STS with lombok plugin installed. You can see this Help -> About Spring Tool Suite sts with lombok

The project can be tested from terminal by running ./gradlew bootRun. You would see a log message Identity Tranformation value is 10 in the console

The same cannot be done from STS as I'm not able to make annotation processors to work

Reproducing the issue I opened earlier in the plugin repo

thekalinga commented 6 years ago

Note that the same configuration works fine in IntelliJ Idea. Just that I manually add annotation processor options over there

thekalinga commented 6 years ago

As per the author of gradle-apt-plugin plugin, STS is configured properly. Which leaves us with two options

  1. STS is not working properly
  2. I have done something wrong

Please let me know which one it is

martinlippert commented 6 years ago

@kdvolder can you have a look and provide a bit of help? Thanks!!!

kdvolder commented 6 years ago

I don't really know why it wouldn't be working. I can only make wild guesses.

Besides the two options above there is also a third one.

  1. The annotation processor(s) are malfunctioning because they don't gracefully deal with incremental compilation. A difference between running builds on the commandline or via IntelliJ is that they typically do 'whole project builds' only. Many annotation processors have not been designed / implemented / tested by their authors in incremental build scenarios and don't work correctly.

It really anyone's guess what is going wrong here. It may require to actually debug the annotation processors themselves to see why they aren't working. Maybe some experiments can be done to try and get more information.

One thing could try is if it works correctly in a 'vanilla' eclipse with buildship. (I.e. without any additions from STS). If it works there then its probably something in STS causing this.

Another thing could be tried is to remove some pieces from the setup you have. Perhaps we can to try to isolate and pinpoint the problem. For example... can you get the mapstruct processor to work by itself (i.e. without introducing lombok in the mix as well). Similarly can you get lombok processor to work by itself?

Finally... I am a bit surprised that you are trying to use lombok as an annotation processor inside of Eclipse. I have not seen anyone else try that before. Typically people using lombok in Eclipse install something directly into eclipse (lombok provides an installer that will modify your eclipse, under the hood it adds a java agent to Eclipse's startup which actually modifies/patches the eclipse compiler). I'm not sure that just configuring the annotation processor designed for CLI use is expected to work in Eclipse environment (as noted earlier, eclipse compiler is more complex than the typical CLI invocation of Javac and many annotation processor do not work properly). Here's some info about the setup of lombok with the java agent https://howtodoinjava.com/automation/lombok-eclipse-installation-examples/

kdvolder commented 6 years ago

I also found this via google and the official mapstruct website:

https://marketplace.eclipse.org/content/mapstruct-eclipse-plugin

So it seems, both mapstruct and lombok are providing another mechanism than an annotation processor to be able to integrate with Eclipse. Perhaps annotation processor are simply not the right way to get them working properly inside of Eclipse?

thekalinga commented 6 years ago

@kdvolder The plugin does not do the compilation part. It parses the POJOs in the classpath & shows suggestions in IDE when writing mappings using mapstruct

Lombok is required when we need to build from the terminal using gradle. Is there another way to build without lombok as a annotation processor dependency?

I just tried in the latest version of eclipse. Have the same issue

thekalinga commented 6 years ago

Where can I open the issue for this?

thekalinga commented 6 years ago

Added more information to an existing eclipse issue

https://bugs.eclipse.org/bugs/show_bug.cgi?id=514055

kdvolder commented 6 years ago

Lombok is required when we need to build from the terminal using gradle. Is there another way to build without lombok as a annotation processor dependency?

No I think you will always need the annotation processors to be part of your gradle build for the build on the CLI to work. I was just questioning whether you need it to work inside of Eclipse too. While I don't use lombok myself I just happened to be aware of the lombok Eclipse extension that some people use to get lombok <-> eclipse integration.

Where can I open the issue for this?

You can try raising several places. Bug against buildship or jdt-apt via https://bugs.eclipse.org/. I see you already tried filing against gradle-apt plugin. You could also try lombok and/or mapstruct.

The trouble is though its not quite clear where to lie blame just yet. Is it BuildShip for not properly configuring the project (or maybe rather the 'gradle-apt-plugin')? Or is it JDT APT which is not properly supporting the two annotation processors you are trying to use, despite them being properly configured? Or is it the lombok and mapstruct processors that might be doing something that doesn't work in Eclipse that they could change (I am reluctant to say that mapstruct / lombok are doing something actually 'wrong' because obviously it works on the CLI, but the fact is that Eclipse incremental compile is more complex than a typical CLI build and it might require special consideration from the processor authors).

There is also still this... There are tools to integrate lombok and mapstruct with Eclipse. So clearly you aren't the first person to try to do that. So its bit surprising it doesn't work for you, and seems there should probably be a way to set these things up so they do actually work properly from Eclipse and the CLI both. I'm just not sure I have much more to offer to help you with that as don't use them myself, and if you are doing something 'wrong' its certainly not obvious to me what it might be.

thekalinga commented 6 years ago

@kdvolder Thanks for your response. I'll for the eclipse team to respond