1

I have a Java Maven project with the following structure. (This is a logical structure, not necessarily the exact directory structure.)

Project
|-Submodule
| |-src/main/java
| |-src/main/resources
| |-src/test/java
| |-src/test/resources
| `-pom.xml
`-pom.xml

In accordance with (my understanding of) Maven standards, the parent pom references the submodule in it's <modules> tag, and the submodule pom references the parent pom as it's <parent>.

Now, my goal is to use Maven to add two new source folders to the submodule, namely src/integrationTest/java and src/integrationTest/resources. I want Maven to "know about" these two folders so that I can execute the tests therein using my Maven testing plugin, maven-pmd-plugin. And I want Eclipse to "know about" these two folders so that they display correctly in Eclipse's graphical Project Explorer.

I was told that the build-helper-maven-plugin plugin could be used to create these additional directories that I needed. So I added the following configuration to my submodule pom:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>add-integration-test-sources</id>
                <phase>generate-test-sources</phase>
                <goals>
                    <goal>add-test-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>src/integration-test/java</source>
                    </sources>
                </configuration>
            </execution>
            <execution>
                <id>add-integration-test-resources</id>
                <phase>generate-test-resources</phase>
                <goals>
                    <goal>add-test-resource</goal>
                </goals>
                <configuration>
                    <resources>
                        <resource>
                            <directory>src/integration-test/resources</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

When I rebuilt the project, Maven didn't generate the directories I wanted. So I took the plugin configuration out of my submodule pom and put it in my parent pom instead. Maven still didn't generate my directories.

At this point, I don't know how to get this plugin working. I'm trying to follow other online tutorials, but I must be doing something wrong. Could anyone explain which pom file is intended to configure build-helper-maven-plugin? And how do I configure Eclipse to display the new Maven project structure correctly?

Thanks for the help!

Mathew Alden
  • 1,458
  • 2
  • 15
  • 34
  • For integration tests you should not create supplemental directories. You should use different naming schemas which already exists (like *IT.java) via the maven-failsafe-plugin. Apart from that you should not generate directories during the build outside `target` folder cause that will produce issues related to your version control.... – khmarbaise Feb 08 '19 at 20:28

1 Answers1

1

khmarbaise's comment made me realize my mistake, although I didn't take his advice.

The build-helper-maven-plugin configuration should go in the submodule pom (not the parent pom) where I originally had it. But Maven will not create these directories for you, you create the directories and then Maven uses them.

Once Maven is using your new directories, Eclipse displays them just fine.

Mathew Alden
  • 1,458
  • 2
  • 15
  • 34