简体   繁体   中英

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.

A simple pom file that has the same behavior looks like:

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

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 .

I am using Eclipse Indigo , m2e 1.2.0 and Maven Integration for WTP 0.15.3 on Debian

Edit

If I remove the properties and hard code the outputs:

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

Try checking your output folders for your Java Build Path. The m2e plugin might be failing to update all the output paths:

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. If you have a look at the Maven Super POM , you can see testOutputDirectory is defined as an element under 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

Sometimes m2e does not pick up changes.

So select your project, right mouse click -> Maven -> Update Project .

在此输入图像描述

If that doesn't help, remove the .settings folder and try again.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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