-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable annotation processing #339
Comments
I've done some tests for eclipse-jdtls/eclipse.jdt.ls#128, but while file generation seems to work, there's an issue with the client detecting changes in the generated files and sending those changes to apply back to the server, so we end up with garbage content. We need to figure out a proper way to cope with generated content, i.e we need to determine whether or not changes from the generated classes folder are caused by something on the server side or by a maven build on the client side. Adding the jar to the server/plugins is not sufficient to load it, one solution would be to embed the m2e-apt jar into a vscode-java extension, but you'll end up with the same issue that I mentioned above. |
Thanks for the feedback. It's a bit hard for me to comment, since I don't know enough about the vscode-java/jdt.ls architecture, but is there any reason the Java language server must be responsible for building your project? Presumably that's not part of the language server protocol? It surprised me initially when I realised that the vscode-java plugin was building my project. I've managed to work around the issue by using the apt-maven-plugin, which afaik uses the jdk 6 annotation processing stuff. This plugin hooks into the 'process' goal, and is picked up by m2e out-of-the-box. Now I can run the Jooby development server while in VSCode and it picks up changes to generated classes no problem now. Great!
|
The server builds the project so that it can detect workspace-wide compilation errors for instance. If you open a generated class in vscode in one pane, while modifying a source triggering modifications to that 1st file in a second pane, you should see some interesting stuff :-) |
We've also got some common scenarios in spring-boot projects that depend on annotation processors to work. I.e. the handling of this kind of stuff: It would be nice if the language server made annotation processors 'just work' out of the box (i.e. not like it is in Eclipse/m2e where you typically have to jump through a bunch of hoops just to enable it, even if the maven build, when run from the CLI 'just works'). I realize this is probably not easy... but we live on hope :-) |
Should this work with Immutables as well? |
Nevermind, I was able to make it work in a fresh project. But I wasn't able to have it working in a big project that I have. Is there any limitation? |
Is Gradle supported as well? Having the following in dependencies {
compile 'com.google.auto.value:auto-value-annotations:1.6.2'
annotationProcessor 'com.google.auto.value:auto-value:1.6.2'
} (Version 0.28.0) |
@simon04 I found a simple workaround for using Gradle with the annotationProcessor features (Immutables, AutoValue, Metamodels). The idea is to add manually the location of the generated sources. In my case, I just had to add sourceSets {
main {
java {
srcDirs = ['src/main/java', 'build/generated/source/apt/main']
}
}
} I don't know if it is a good idea or whatever, but it works and helps me get the job done 😁 |
Can someone explain under the hood what vscode-java is doing, so we can reproduce it in other lsp clients? Is this changing the javaagent or bootclasspath args to the jvm like for Lombok? Or is this modifying the .classpath or .settings JDT project ? |
You just need to configure your project properly. Java LS, not vscode-java, will do what is necessary. |
What if I don't use Gradle and don't use Maven? |
I see, so it seems all the Eclipse JDT server needs is a |
|
I want to use the annotation processor without build tools. I have tried to add references to the processor in the project launch.json file but it doesn't work. In which file should I modify to add the processor to javac? Thanks! |
@snjeza I'm also not using any build tools. I'm not able to figure out the exact steps to get the Annotation processing to work in VSC. Could you please elaborate a bit more? Thanks. |
@deepfriedbrain could you attach a project example? |
@snjeza It's an enterprise project with proprietary code. It is a Java project and not using any build tools such as Maven or Gradle. |
According to https://github.com/redhat-developer/vscode-java/wiki/Annotation-Processing-support-for-Maven-projects, |
Hi, I'm trying to use https://github.com/immutables/immutables which is an annotation based source code generator.
In the docs (https://immutables.github.io/apt.html), it's mentioned that the m2e-apt Eclipse plugin needs to be configured when building in Eclipse, so presumably this is why in vscode it doesn't work?
I was previously having problems with Rocker templates, and with hindsight this might have been related.
Environment
Steps To Reproduce
https://immutables.github.io/getstarted.html
org.immutables
dependency@Value.Immutable
annotationCurrent Result
No generated source code for
@Value.Immutable
annotated classExpected Result
Corresponding
Immutable...
class source code generatedAdditional Informations
I tried adding
org.jboss.tools.maven.apt.core_1.3.0.201610261805
to the extension's server/plugins folder to see if that allowed the annotation processor to be picked up, but it wasn't effective. I also tried putting the Immutables jar in theannotationProcessorPaths
element in the maven compile plugin configuration, but it still wasn't picked up.The text was updated successfully, but these errors were encountered: