> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/maven/plugins/customization-and-enhancement/build-helper-maven-plugin.md). Agents can also search and read this documentation through its [MCP server](https://www.pranaypourkar.co.in/the-programmers-guide/~gitbook/mcp).

# build-helper-maven-plugin

## About

It is a useful Maven plugin provided by the Mojo project **"org.codehaus.mojo"**. It helps in managing various aspects of the build process. Some of the ways in which it helps is given below.

* Add more source directories to the project
* Add more test source directories to your project
* Add more resource directories to your project
* Attach additional artifacts to your project
* Access the parsed components of a project version (properties then can be used in other parts of the Maven build or in the POM configuration)
* Resolve the latest released version of a project
* Remove a project's artifacts from local repository
* Reserve a list of random and unused network ports
* Retrieve current host IP address
* Retrieve current hostname
* Retrieve available number of CPUs

Visit the official documentation for more details - <https://www.mojohaus.org/build-helper-maven-plugin/usage.html>

**Example 1**: Adding source and test directories to the build path.

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-7d62d34eaeba209b83f9578c29d6b44b8a69bf2f%2Fimage.png?alt=media" alt="" width="330"><figcaption></figcaption></figure>

```xml
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <!-- Add more source directories from target folder to the project -->
        <execution>
            <id>add-build-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/generated-sources</source>
                </sources>
            </configuration>
        </execution>
        <!-- Add more source directories from main-2 folder to the project -->
        <execution>
            <id>add-main-2-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${basedir}/src/main-2/java</source>
                </sources>
            </configuration>
        </execution>
        <!-- Add more resource directories from main-2 folder to the project -->
        <execution>
            <id>add-main-2-resources</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>add-resource</goal>
            </goals>
            <configuration>
                <resources>
                    <resource>
                        <directory>${basedir}/src/main-2/resources</directory>
                        <targetPath>resources</targetPath>
                        <excludes>
                            <exclude>**/junk/**</exclude>
                        </excludes>
                    </resource>
                </resources>
            </configuration>
        </execution>
        <!-- Add more test source directories from test-2 folder to the project -->
        <execution>
            <id>add-test-2-sources</id>
            <phase>generate-test-sources</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${basedir}/src/test-2/java</source>
                </sources>
            </configuration>
        </execution>
        <!-- Add more test resource directories from test-2 folder to the project -->
        <execution>
            <id>add-test-2-resource</id>
            <phase>generate-test-resources</phase>
            <goals>
                <goal>add-test-resource</goal>
            </goals>
            <configuration>
                <resources>
                    <resource>
                        <directory>${basedir}/src/test-2/resources</directory>
                        <targetPath>resources</targetPath>
                        <excludes>
                            <exclude>**/junk/**</exclude>
                        </excludes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
```

> Run `mvn clean compile` or click on load maven changes button in Intellij in pom.xml file to reflect the changes.
>
> <img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-7cf72e5e007b2d93b927f638b0dd789df05fafe3%2Fimage.png?alt=media" alt="" data-size="original">


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/maven/plugins/customization-and-enhancement/build-helper-maven-plugin.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
