0

我希望遵循 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”,但我的实际文件结构似乎没有任何变化。我应该在某处看到“src/it/java”,对吗?相反,即使在关闭并打开项目并点击刷新之后,我得到的只是:在此处输入图像描述

4

1 回答 1

1

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

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

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

  2. 现在选择Build Path,您应该src/it/java会在 Source 选项卡中看到缺少的源文件夹。

但是为了让它以您期望的花哨形式出现在项目资源管理器中,该目录实际上应该由其他插件存在/生成。

于 2014-10-18T16:38:12.603 回答