A VS Code extension that detects Maven projects using swagger-codegen-maven-plugin and offers to add build-helper-maven-plugin so that IDEs correctly include generated sources on the classpath.
When using swagger-codegen-maven-plugin, the generated Java sources end up in target/generated-sources/swagger/src/main/java. Without build-helper-maven-plugin, IDEs like VS Code and IntelliJ may not automatically add this path to the project's source folders, leading to unresolved imports and red squiggles.
- On workspace open, scans all
pom.xmlfiles for the presence ofswagger-codegen-maven-plugin. - For each match, checks whether
build-helper-maven-pluginis already configured. - If the plugin is missing, shows a notification toast offering to add it automatically.
- When accepted, inserts the following plugin at the end of the
<plugins>section in the<build>block:
<plugin>
<!-- a hint for IDEs 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>- Automatic: The extension activates whenever a workspace contains a
pom.xml. It checks all Maven projects on startup. - Manual: Run the command
Maven Codegen Helper: Check Projectsfrom the Command Palette (Cmd+Shift+P). - On save: When you save a
pom.xml, the extension re-checks that file.
cd maven-codegen-helper
npm install
npm run compileThen press F5 in VS Code to launch the Extension Development Host.
npm install -g @vscode/vsce
vsce packageThis produces a .vsix file you can install via Extensions: Install from VSIX... in VS Code.
- VS Code 1.80+
- A Maven project with
pom.xmlin the workspace