You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to handle extra classpath from generated code #177
I'm using Google's AutoValue and Protocol Buffer, both which generate source code under build/generated/source/.... However, each time I start vscode, this java plugin would automatically create a new .classpath file that overrides my manual edit.
Is the plugin going to handle the generated source code? Is there a workaround for now? Thanks.
Reacted by Richard Kolkovich, Raul, Jackie Li, Giampiero De Ciantis, Jeff Martin, Roman Rudakov, Ciaran Lawlor, Johan Mudsam, Jiang Wei, Aarash Yaadegarnia and 27 more
we event try to add it to the test class path like so (not needed for mvn install to work).
<plugin>
<!-- a hint for IDE's to add the java sources to the classpath -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>01-add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
There seems to be support specifically for build-helper-maven-plugin. However, there are lots of plugins which generate sources and add them to the classpath, usually under target/generated-sources. In this case, build-helper-maven-plugin is not required. VS Code should automatically recognize this. Directories like target/generated-sources and target/generated-resources could be automatically added. Alternatively, an option to configure additional classpath folders per Maven module would be welcome.
Reacted by emmanueltouzery, Carsten W., Riccardo De Benedictis, Jan Pieter Wijbenga, zofari, kikogolk, Maik Toepfer, Charlie Zha, Sioxas, Sławomir Bażant and 28 more
Same here. We generate Pojos for XML schemas using the jaxb2-maven-plugin. By default does classes are placed in target/generated-sources/jaxb/com/mypackage/MyGeneratedClass.java
Is there a chance to add a classpath by hand in VC code?
There seems to be support specifically for build-helper-maven-plugin. However, there are lots of plugins which generate sources and add them to the classpath, usually under target/generated-sources. In this case, build-helper-maven-plugin is not required. VS Code should automatically recognize this. Directories like target/generated-sources and target/generated-resources could be automatically added. Alternatively, an option to configure additional classpath folders per Maven module would be welcome.
I have this work project that places a few packages inside target/generated-sources and target/generated-resources and these are not being picked up by the plugin. Making it impossible for me to use VS Code with these Java projects.
Guys, if you want to make sure your use case is covered eventually, please add some small sample projects using various maven plugins contributing source folders.
In my Gradle based project I was able to fix the problem that VS Code complains about a missing generated class by explicitly adding the directory of the generated classes to the source sets in the Gradle build script build.gradle:
It is a great clue. However, the srcDirs 'build/generated/sources/annotationProcessor/java/main' does not work for me.
I just changed a bit to fix it. The following configuration works for me.
Note:
I used gradle init to create the project, so the src and build are under app directory. You may not have app, so you can remove it from the path.
Not to add clutter to this issue, but I also cannot come up with a workaround for my gradle project. I have one generated source code folder and I would like to add it as a one off, but I don't want to mess up any of the other auto class path generation. Lots of talk about Maven but not much about gradle :/
This is an existing intellij project that I really want to run in vs code because I love vs code 😭
The problem I see is not that the generated sources are not added in the .classpath, but the grpc files are not generated or removed. Whenever I re-open the project, it removes the generated sources...
This will disable initializationOptions.settings.java.autobuild.enabled in workspace initialisation. You can manually build it if it wasn't built before. More details in the README.md of this project
There should be a similar option in vscode-java as coc-java is forked from this.
Same issue here - was using VScode just fine until a new dependency wrote to target/generated-sources/xyz and VsCode is not picking up the classes from there.
The main thing i wanted to resolve was getting the tests to be able to run individually within the vscode ide
I solved it by modifying the setting.json per the below code
note only the source paths key was necessary Settings.json
I found this helpful too, I think it helps with some vs-code server logic with working out how to package the classes in generated-sources with a snippet from pom Pom.xml
<plugin>
<!-- a hint for IDE's to add the java sources to the classpath -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<?m2e execute onConfiguration,onIncremental?>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/swagger/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
This issue is particularly painful when working with JPAStreamer.
Really strange that mapstruct works but not JPAStreamer, even with org.codehaus.mojo:build-helper-maven-plugin added to pom
Activity
fbricon commentedon Apr 1, 2017
Are you using Maven or Gradle?
With Maven, if you configure build-helper-maven-plugin, vscode-java 0.1.0 should setup the classpath accordingly.
Could you please attach a sample project?
fbricon commentedon May 30, 2017
@minkyn ping. See previous comment
fbricon commentedon Aug 24, 2017
That seems like a duplicate of #285. @minkyn are you using gradle?
IzakMarais commentedon Mar 9, 2018
I have the same problem when using Maven to generate protocol buffer sources.
Source files are generated like so in the pom:
we event try to add it to the test class path like so (not needed for
mvn installto work).IzakMarais commentedon Mar 9, 2018
The problem is compounded by interaction with #322. Since I often need to close VSCode to get tests to run, the classpath gets messed up often.
unguiculus commentedon Dec 11, 2018
There seems to be support specifically for
build-helper-maven-plugin. However, there are lots of plugins which generate sources and add them to the classpath, usually undertarget/generated-sources. In this case,build-helper-maven-pluginis not required. VS Code should automatically recognize this. Directories liketarget/generated-sourcesandtarget/generated-resourcescould be automatically added. Alternatively, an option to configure additional classpath folders per Maven module would be welcome.samba2 commentedon Apr 9, 2019
Same here. We generate Pojos for XML schemas using the jaxb2-maven-plugin. By default does classes are placed in
target/generated-sources/jaxb/com/mypackage/MyGeneratedClass.javaIs there a chance to add a classpath by hand in VC code?
rfgamaral commentedon Jun 3, 2019
@fbricon Any comments on the above?
I have this work project that places a few packages inside
target/generated-sourcesandtarget/generated-resourcesand these are not being picked up by the plugin. Making it impossible for me to use VS Code with these Java projects.rmannibucau commentedon Jun 3, 2019
Hello,
Any hope this issue gets addressed? It prevents to use java-templating plugin, CXF plugins, and a bunch of other plugins.
Thanks a lot for the hard work,
Romain
fbricon commentedon Jun 3, 2019
Sure, we'll investigate this in the near feature. Can't commit to a timeframe though.
fbricon commentedon Jun 3, 2019
Guys, if you want to make sure your use case is covered eventually, please add some small sample projects using various maven plugins contributing source folders.
rmannibucau commentedon Jun 3, 2019
@fbricon here it is https://github.com/rmannibucau/generated-sources-demo, just try to code/compile in Main.java through vscode (works in CLI), it will miss the two generated folder created by java-templating and wadl cxf plugin.
fbricon commentedon Jun 3, 2019
@rmannibucau I cloned it, ran a CLI build, opened vscode, the source folders have been added to the classpath automatically:
28 remaining items
Change location of generated OpenAPI sources
wxw-matt commentedon May 21, 2022
Solved!
It is a great clue. However, the
srcDirs 'build/generated/sources/annotationProcessor/java/main'does not work for me.I just changed a bit to fix it. The following configuration works for me.
Note:
mdgozza commentedon Aug 22, 2022
Not to add clutter to this issue, but I also cannot come up with a workaround for my gradle project. I have one generated source code folder and I would like to add it as a one off, but I don't want to mess up any of the other auto class path generation. Lots of talk about Maven but not much about gradle :/
This is an existing intellij project that I really want to run in vs code because I love vs code 😭
timvahlbrock commentedon Nov 2, 2022
Problem also occurs when using javaCC, even when m2e execution hint is added to pom.xml.
davidivkovic commentedon Nov 3, 2022
Still completely broken
jackieli-tes commentedon Nov 21, 2022
I found a workaround using this sample repo: https://github.com/jackielii/grpc-java-example. Using coc.nvim, in CocLocalConfig or global one, set:
This will disable
initializationOptions.settings.java.autobuild.enabledin workspace initialisation. You can manually build it if it wasn't built before. More details in the README.md of this projectThere should be a similar option in vscode-java as coc-java is forked from this.
manuelserradev commentedon Feb 4, 2023
I'd like to reference this comment with a repro project.
The generated sources are correctly generated by vscode but cannot be referenced in user code.
kopiro commentedon Jun 2, 2023
Same issue here - was using VScode just fine until a new dependency wrote to
target/generated-sources/xyzand VsCode is not picking up the classes from there.pythonpadawanEXE commentedon Sep 7, 2023
The main thing i wanted to resolve was getting the tests to be able to run individually within the vscode ide
I solved it by modifying the setting.json per the below code
note only the source paths key was necessary
Settings.json
I found this helpful too, I think it helps with some vs-code server logic with working out how to package the classes in generated-sources with a snippet from pom
Pom.xml
This was a useful resource to collate the discussion topics on this issue

https://github.com/redhat-developer/vscode-java/blob/master/document/_java.notCoveredExecution.md
Realistically the class paths needs to be setup correctly on vscode with the java extension pack and should be shown correctly on the configure java path settings page
Fabccc commentedon Jan 22, 2025
This issue is particularly painful when working with JPAStreamer.
Really strange that mapstruct works but not JPAStreamer, even with
org.codehaus.mojo:build-helper-maven-pluginadded to pombmarwell commentedon Apr 13, 2025
Sometimes I wish we could get paid support, like we have for IntelliJ.