Search code examples
mavenspring-tool-suitebuild-helper-maven-plugin

Maven plugin Build Helper not creating new directories in Spring Tool Suite workspace


I'm looking to follow the advice in the book Spring in Practice chapter 10 on creating separate directories for unit tests and integration tests using the Build Helper plugin in Maven. I'm working in Spring Tool Suite trying to add integration tests to a Spring project. I configured the plugin as follows:

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

I run the build using clean and I try it again just using compile. I receive the following on my console screen:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building wellness Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- build-helper-maven-plugin:1.9.1:add-test-source (add-it-source) @ wellness ---
[INFO] Test Source directory: /Users/walk12/Documents/workspace-sts/wellness/src/it/java added.
[INFO] 
[INFO] --- build-helper-maven-plugin:1.9.1:add-test-resource (add-it-resource) @ wellness ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ wellness ---
[WARNING] Using platform encoding (US-ASCII actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ wellness ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding US-ASCII, i.e. build is platform dependent!
[INFO] Compiling 6 source files to /Users/walk12/Documents/workspace-sts/wellness/target/classes
[WARNING] /Users/walk12/Documents/workspace-sts/wellness/src/main/java/com/kylewalker/wellness/data/EmployeeDaoJdbcImpl.java: /Users/walk12/Documents/workspace-sts/wellness/src/main/java/com/kylewalker/wellness/data/EmployeeDaoJdbcImpl.java uses unchecked or unsafe operations.
[WARNING] /Users/walk12/Documents/workspace-sts/wellness/src/main/java/com/kylewalker/wellness/data/EmployeeDaoJdbcImpl.java: Recompile with -Xlint:unchecked for details.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.374 s
[INFO] Finished at: 2014-10-18T07:48:37-07:00
[INFO] Final Memory: 15M/153M
[INFO] ------------------------------------------------------------------------`

It's saying that "/Users/walk12/Documents/workspace-sts/wellness/src/it/java added", but nothing seems to change in my actual file structure. I should be seeing "src/it/java" somewhere, correct? Instead, even after closing and opening the project and hitting Refresh, all I get is: enter image description here


Solution

  • build-helper-maven-plugin:add-test-source is used to add additional test source directories to the build context. This doesn't mean that it will actually create any new directories. It just means that it will just add an existing set of directories to the build. These directories can be something manually created by you or it might be created by some other plugin during the build.

    Assuming that you have already installed the buildhelper m2e connector, m2e should have added src/it/java as a test source folder. You can verify this following the below steps

    1. Right click on the project and click Properties

    2. Now select Build Path and you should see src/it/java as a missing source folder in the Source tab.

    But for it to appear in the Project Explorer in the fancy form which you expect, the directory should actually be present/generated by some other plugin.