jbosstools / m2e-apt

Maven integration with Eclipse JDT Annotation Processor Toolkit
39 stars 19 forks source link

.factorypath lacks jars, when corresponding projects are opened in Eclipse #64

Open basinilya opened 6 years ago

basinilya commented 6 years ago

I have a project that generates sources correctly when it's opened alone, but if I import its dependencies in Eclipse, it can no longer geneate sources. That's because the generated .factorypath doesn't have entries that correspond to the projects opened in Eclipse.

As a workaround please deduce the "M2_REPO/*/.jar" path from the dependency projects' GAV and add to .factorypath.

fbricon commented 6 years ago

Sorry, workspace dependencies are not supported by the underlying JDT APT engine, so we can't add them to the .factorypath.

You can try to delegate AP to the maven plugin instead of JDT APT, but it's not guaranteed to work anyway. Add the following property to your pom.xml's properties block:

`maven_plugin</m2e.apt.activation>

basinilya commented 6 years ago

workspace dependencies are not supported

I know that and this is why I'm asking you to use the repo jars regardless.

basinilya commented 6 years ago
maven_plugin

This doesn't seem to have any effect at all, neither does the global setting in Window Preferences

dsyer commented 6 years ago

I have the same problem, or possibly something similar. In my case the APT project is not even a dependency of the target project (the one that won't build), but it is in the maven-compiler-plugin configuration. The processor just happens to be something I'm working on, so it is open in Eclipse. If I switch off the Maven project nature for the processor project then everything magically starts working, but (obviously) that isn't very convenient, since it is a Maven project.

If you look at what happens to the Java Compiler settings when you right click and Maven -> Update Project..., you can see what the problem is: it is not that the .factorypath is wrong, it is simply that annotation processing is switched off in the JDT settings. You can switch it "on" manually, and as long as the .factorypath is pre-computed to something correct, it will work, but only until the next time you do Maven -> Update project.... If m2e could leave that flag "on" on and go ahead and calculate the factory path from the locally cached processor jar, everything would work fine.

So to be clear, I understand there might be a limitation in Eclipse that prevents changes in the APT processor from being immediately reflected in other projects in the workspace, but I do not see why it needs to be switched off completely. I'm quite happy in this case to manually build and install the processor when it changes.

UPDATE: even more odd (and there's an ugly a workaround somewhere, although not very practical for "production" use), I find that if I add another APT processor in the maven-compiler-plugin in addition to my own local one, then m2e switches APT processing back on. It doesn't add my local APT processor to the factory path, so it is still broken, but I could trick it into working by faking the dependencies in the additional processor.

mickaelistria commented 2 years ago

m2e-apt's code is now included in https://github.com/eclipse-m2e/m2e-core , please consider reporting issue to https://github.com/eclipse-m2e/m2e-core/issues if it's still relevant.