javavscode icon indicating copy to clipboard operation
javavscode copied to clipboard

Include generated sources in Source packages

Open akshay-tamhane opened this issue 1 year ago • 1 comments

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?

akshay-tamhane avatar Dec 09 '23 19:12 akshay-tamhane

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.

jglick avatar May 30 '24 18:05 jglick

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.

Achal1607 avatar Sep 03 '24 06:09 Achal1607

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.

jglick avatar Sep 04 '24 16:09 jglick