oracle / javavscode

Java platform support for Visual Studio Code for full featured Java development (edit-compile-debug & test cycle)
Apache License 2.0
232 stars 31 forks source link

Include generated sources in Source packages #91

Closed akshay-tamhane closed 3 months ago

akshay-tamhane commented 11 months ago

In a maven project, there are generated java files which are present in a folder called "gen" other than the "main" folder, under the src folder. However, these packages are not detected by this extension and gives an error "package does not exist". Is there any way to make this work for code completion/navigation by marking the "gen" folder as one of the source packages?

jglick commented 6 months ago

Conventionally these should be placed in a package root which is a subdirectory of target/generated-sources (or target/generated-test-sources in the case of test scope); for example target/generated-sources/stuff-from-my-maven-plugin/com/mycorp/SomeClass.java.

Achal1607 commented 3 months ago

Hey @akshay-tamhane, There is a plugin that you need to add in your pom.xml with appropriate configurations. I have attached a example snippet which should work most probably (atleast it is working for me currently).

<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/gen/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Closing this issue for now, feel free to reopen this issue if you have any more queries.

jglick commented 2 months ago

I would really recommend use of target/generated-sources/<somedir>/ instead. This follows Maven conventions, works with mvn clean, and will be honored automatically by the IDE.