# 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="/files/fCICAu0rlJDsDmmDuNJP" 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="/files/eL1dj9puvI6qiw45ARlZ" alt="" data-size="original">


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
