Maven插件Build Helper不在Spring Tool Suite工作区中创建新目录

时间:2014-10-18 14:34:03

标签: maven spring-tool-suite build-helper-maven-plugin

我希望遵循Spring in Practice第10章中关于使用Maven中的Build Helper插件为单元测试和集成测试创建单独目录的建议。我正在使用Spring Tool Suite尝试将集成测试添加到Spring项目中。我按如下方式配置了插件:

<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>

我使用clean运行构建,然后使用compile再次尝试。我在控制台屏幕上收到以下信息:

[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] ------------------------------------------------------------------------`

它说“/ Users / walk12 / Documents / workspace -sts / wellness / src / it / java added”,但在我的实际文件结构中似乎没有任何变化。我应该在某处看到“src / it / java”,对吗?相反,即使在关闭并打开项目并点击刷新之后,我得到的只是:enter image description here

1 个答案:

答案 0 :(得分:1)

build-helper-maven-plugin:add-test-source用于向构建上下文添加其他测试源目录。这并不意味着它实际上会创建任何新目录。它只是意味着它只会将一组现有目录添加到构建中。这些目录可以是您手动创建的,也可以是在构建期间由其他插件创建的。

假设您已经安装了buildhelper m2e连接器,m2e应该添加src/it/java作为测试源文件夹。您可以按照以下步骤进行验证

  1. 右键单击该项目,然后单击Properties

  2. 现在选择Build Path,您应该会看到src/it/java作为缺失来源     “源”选项卡中的文件夹。

  3. 但是为了让它以您期望的花哨形式出现在Project Explorer中,该目录实际上应该由其他插件存在/生成。