0

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

Kyle Walker
  • 559
  • 3
  • 12
  • 25
  • Does it appear under the src folder hierarchy in your project view (i.e. the folder src folder with the red problem marker in your screenshot)? My guess is that Eclipse m2e doesn't know that src/it/java is a Java source folder (since this doesn't follow the usual maven conventions). – Drew MacInnis Oct 18 '14 at 15:12
  • I guess that `build-helper-maven-plugin` adds paths to the Maven build structure but does not create the directories. Do `src/it/java` and `src/it/resources` already exist? And also try to update the maven project in Eclipse. You have an error there, it maybe pointing to something, presumably, missing directories. – lexicore Oct 18 '14 at 16:36
  • @DrewMacInnis If the paths are added to the Maven build structure (and the `build-helper-maven-plugin` does exactly that), m2eclipse must pick them up. – lexicore Oct 18 '14 at 16:37
  • The red X is for a .jsp file in WEB-INF. – Kyle Walker Oct 18 '14 at 18:08

1 Answers1

1

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.

coderplus
  • 5,793
  • 5
  • 34
  • 54
  • Well, nice to see you again, @coderplus. :) My guess is also that the directory is missing. – lexicore Oct 18 '14 at 16:40
  • OK, I was thinking that this plugin created the directories as well. I checked in Properties>Build Path, and the src/it/java folder is not indicated there in any way. Can I simply right-click and create these directories myself? Is there anything else I'm supposed to do in order to do this properly? – Kyle Walker Oct 18 '14 at 18:12
  • @Kyle Walker - yes you can create the directories and add the required test cases and test resources. Which version of eclipse and m2e are you using. Do you have the buildhelper connector installed? – coderplus Oct 18 '14 at 18:16
  • @coderplus - I'm actually using Spring Tool Suite, which is a version of Eclipse. (I just changed my question and title to reflect this oversight on my part.) It's version 3.6.2. The version of m2e is 1.5.0140606-0033, and I see an "m2e connector for build-helper-maven-plugin" that has a version of 0.15.0.201207090124. – Kyle Walker Oct 18 '14 at 19:55
  • Right click on the project > Maven > Update project configuration from pom file and check the source tab once again. – coderplus Oct 18 '14 at 21:16
  • @coderplus - I checked the build path source and it's there now, indicating the folders are missing. Thanks! I should just be able to manually add the folders now. I really appreciate the help! – Kyle Walker Oct 19 '14 at 01:54