【发布时间】:2014-12-13 23:20:30
【问题描述】:
我希望遵循 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”,对吗?相反,即使在关闭并打开项目并点击刷新后,我得到的只是:
【问题讨论】:
-
它是否出现在项目视图中的 src 文件夹层次结构下(即屏幕截图中带有红色问题标记的文件夹 src 文件夹)?我的猜测是 Eclipse m2e 不知道 src/it/java 是一个 Java 源文件夹(因为这不遵循通常的 maven 约定)。
-
我猜
build-helper-maven-plugin将路径添加到 Maven 构建结构但不创建目录。src/it/java和src/it/resources是否已经存在?并尝试在 Eclipse 中更新 maven 项目。你有一个错误,它可能指向某些东西,大概是缺少目录。 -
@DrewMacInnis 如果路径被添加到 Maven 构建结构中(
build-helper-maven-plugin正是这样做的),m2eclipse 必须选择它们。 -
红色 X 表示 WEB-INF 中的 .jsp 文件。
标签: maven spring-tool-suite build-helper-maven-plugin