简体   繁体   English

m2e忽略测试资源的testOutputDirectory

[英]m2e ignores the testOutputDirectory for test resources

I have a requirement to output my build to a different directory to target . 我需要将我的构建输出到目标的不同目录。

Using the project.build.directory , output and testOutputDirectory properties works correctly from the command line using mvn clean install , but when I build from eclipse it creates an empty target/test-classes directory if I have a src/test/resources directory. 使用project.build.directory输出testOutputDirectory属性可以使用mvn clean install从命令行正常工作,但是当我从eclipse构建时,如果我有一个src/test/resources目录,它会创建一个空的target/test-classes目录。

A simple pom file that has the same behavior looks like: 具有相同行为的简单pom文件如下所示:

<project>
    <groupId>com.example</groupId>
    <version>1.0.0</version>    
    <modelVersion>4.0.0</modelVersion>
    <artifactId>reproduce</artifactId>
    <packaging>war</packaging>
    <properties>
        <project.build.directory>differentTarget</project.build.directory>
        <project.build.outputDirectory>${project.build.directory}/classes</project.build.outputDirectory>
        <project.build.testOutputDirectory>${project.build.directory}/different-test-classes</project.build.testOutputDirectory>
    </properties>

    <build>
        <directory>${project.build.directory}</directory>
        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
        <testOutputDirectory>${project.build.testOutputDirectory}</testOutputDirectory>
    </build>
</project>

My directory structure looks like: 我的目录结构如下:

   |-src
   |---main
   |-----webapp
   |-------WEB-INF
   |---test
   |-----resources

The simplest way I can reproduce the behavior is with all the directories empty except for a web.xml with <web-app /> inside it. 我可以重现行为的最简单方法是将所有目录清空,除了其中包含<web-app />的web.xml。

When I have actual test classes it creates folders inside the target/test-classes directory but then puts the actual class files in differentTarget/test-classes . 当我有实际的测试类时,它会在target/test-classes目录中创建文件夹,但是然后将实际的类文件放在differentTarget/test-classes

I am using Eclipse Indigo , m2e 1.2.0 and Maven Integration for WTP 0.15.3 on Debian 我在Debian上使用Eclipse Indigom2e 1.2.0Maven Integration for WTP 0.15.3

Edit 编辑

If I remove the properties and hard code the outputs: 如果我删除properties并硬编码输出:

<build>
    <directory>differentTarget</directory>
    <outputDirectory>differentTarget/classes</outputDirectory>
    <testOutputDirectory>differentTarget/different-test-classes</testOutputDirectory>
</build>

Then I get the correct behavior when I go Maven > Update Project... but I still get the incorrect target folder when I go Project > Clean or more importantly have it on Build Automatically . 然后当我进入Maven> Update Project时,我得到了正确的行为...但是当我去Project> Clean或者更重要的是在Build Automatically上有它时,我仍然得到不正确的目标文件夹。

Try checking your output folders for your Java Build Path. 尝试检查Java Build Path的输出文件夹。 The m2e plugin might be failing to update all the output paths: m2e插件可能无法更新所有输出路径:

Right click your project -> Build Path -> Configure Build Path. 右键单击您的项目 - >构建路径 - >配置构建路径。

On the Source tab expand each entry, edit the Output Folder and switch each one back to the project default. 在“源”选项卡上展开每个条目,编辑“输出文件夹”并将每个条目切换回项目默认值。

By default all maven POM inherit the Super POM. 默认情况下,所有maven POM都继承Super POM。 If you have a look at the Maven Super POM , you can see testOutputDirectory is defined as an element under project/build. 如果你看一下Maven Super POM ,你可以看到testOutputDirectory被定义为project / build下的一个元素。 I'm not sure if you meant to set it as a property. 我不确定你是否打算将它设置为财产。 Try override the element <testOutputDirectory> directly under your <build> section 尝试直接在<build>部分下覆盖<testOutputDirectory>元素

Sometimes m2e does not pick up changes. 有时m2e不会发现变化。

So select your project, right mouse click -> Maven -> Update Project . 因此,选择您的项目, 单击鼠标右键 - > Maven - >更新项目

在此输入图像描述

If that doesn't help, remove the .settings folder and try again. 如果这没有帮助,请删除.settings文件夹,然后重试。

Edit: 编辑:

Maybe it can't translate the properties used in the build section. 也许它无法翻译构建部分中使用的属性。 Try hardcoded: 尝试硬编码:

 <build>
    <directory>differentTarget</directory>
    <outputDirectory>differentTarget/classes</outputDirectory>
    <testOutputDirectory>differentTarget/different-test-classes</testOutputDirectory>
 </build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM