【问题标题】:Maven plugin Build Helper not creating new directories in Spring Tool Suite workspaceMaven 插件 Build Helper 不在 Spring Tool Suite 工作区中创建新目录
【发布时间】: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


【解决方案1】:

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

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

  1. 右键项目,点击Properties

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

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

【讨论】:

  • 好吧,很高兴再次见到你,@coderplus。 :) 我的猜测也是该目录丢失了。
  • 好的,我在想这个插件也创建了目录。我检查了属性>构建路径,并且没有以任何方式指示 src/it/java 文件夹。我可以简单地右键单击并自己创建这些目录吗?为了正确地做到这一点,我还应该做些什么吗?
  • @Kyle Walker - 是的,您可以创建目录并添加所需的测试用例和测试资源。您使用的是哪个版本的 eclipse 和 m2e。您是否安装了 buildhelper 连接器?
  • @coderplus - 我实际上使用的是 Spring Tool Suite,它是 Eclipse 的一个版本。 (我刚刚更改了我的问题和标题以反映我的这种疏忽。)它的版本是 3.6.2。 m2e 的版本是 1.5.0140606-0033,我看到一个“m2e connector for build-helper-maven-plugin”的版本是 0.15.0.201207090124。
  • 在项目上右击 > Maven > 从 pom 文件更新项目配置并再次检查源选项卡。
猜你喜欢
  • 2021-07-30
  • 1970-01-01
  • 2017-09-10
  • 1970-01-01
  • 2014-04-24
  • 2015-05-14
  • 1970-01-01
  • 2020-01-06
  • 1970-01-01
相关资源
最近更新 更多