Maven Eclipse Plugin
  1. Maven Eclipse Plugin
  2. MECLIPSE-422

Cannot specify a separate output directory for test classes when custom buildOutputDirectory set

    Details

    • Number of attachments :
      3

      Description

      As soon as buildOutputDirectory is set to a non-default value the output directories for all source folders are the same. It should be possible to specify a buildTestOutputDirectory to separate main and test classes, as is the default behaviour when buildOutputDirectory is not set.

      1. fakeBuildOutputDirectory.patch
        5 kB
        Hannu Leinonen
      2. separateOutputs.patch
        1 kB
        Andrea Aime
      3. testOutputDirectory.patch
        4 kB
        Andrea Aime

        Issue Links

          Activity

          Hide
          Rustam Abdullaev added a comment - - edited

          buildOutputDirectory is useless; I can't think of a scenario in which one would want to mix test- and non-test folders, but it seems like the plugin was designed that way, according to this comment in EclipsePlugin.java:
          // If using the standard output location, don't mix the test output into it.

          A possible workaround:
          Specify the output directory at the project level under /project/build, for example, like this:
          <outputDirectory>WebContent/WEB-INF/classes</outputDirectory>
          And don't specify buildOutputDirectory - the eclipse plugin will automatically use the default outputDirectory for non-test classes only.

          Note For a web app, also specify correct webapp path under /project/build/plugins/plugin[artifactId="maven-war-plugin"]/configuration, like this:
          <warSourceDirectory>WebContent</warSourceDirectory>

          Show
          Rustam Abdullaev added a comment - - edited buildOutputDirectory is useless; I can't think of a scenario in which one would want to mix test- and non-test folders, but it seems like the plugin was designed that way, according to this comment in EclipsePlugin.java: // If using the standard output location, don't mix the test output into it. A possible workaround: Specify the output directory at the project level under /project/build, for example, like this: <outputDirectory>WebContent/WEB-INF/classes</outputDirectory> And don't specify buildOutputDirectory - the eclipse plugin will automatically use the default outputDirectory for non-test classes only. Note For a web app, also specify correct webapp path under /project/build/plugins/plugin [artifactId="maven-war-plugin"] /configuration, like this: <warSourceDirectory>WebContent</warSourceDirectory>
          Hide
          Andrea Aime added a comment - - edited

          Very much agreed. In GeoTools and GeoServer projects we would like to use a separate Eclipse output directory but at the moment it's not possible due to this very issue, as we have test resources that do overwrite main resources with the same name. Both are related to the respective plugin systems, which look for a certain file in the jars, and the tests, that in order to double check the plugin system itself, use files with the same name to install test plugins.

          The separateOutputs.patch file is a trivial patch that makes it so the output of src and test end up in different directories fixing the problem for us. The intent is to consider the outputDirectory not as the directory where the classes will be put, but as the root for the main and source output directories, which will be kept separate. When the outputDirectory is set to $OUTPUT, the main sources and resources will be targeted to $OUTPUT/classes, whilst the test ones to $OUTPUT/test-classes.

          If this behaviour change is not acceptable I'm ready to prepare a patch that will add a testOutputDirectory parameter instead.
          Oh, I coded the patch against the 2.7 releases sources.

          Show
          Andrea Aime added a comment - - edited Very much agreed. In GeoTools and GeoServer projects we would like to use a separate Eclipse output directory but at the moment it's not possible due to this very issue, as we have test resources that do overwrite main resources with the same name. Both are related to the respective plugin systems, which look for a certain file in the jars, and the tests, that in order to double check the plugin system itself, use files with the same name to install test plugins. The separateOutputs.patch file is a trivial patch that makes it so the output of src and test end up in different directories fixing the problem for us. The intent is to consider the outputDirectory not as the directory where the classes will be put, but as the root for the main and source output directories, which will be kept separate. When the outputDirectory is set to $OUTPUT, the main sources and resources will be targeted to $OUTPUT/classes, whilst the test ones to $OUTPUT/test-classes. If this behaviour change is not acceptable I'm ready to prepare a patch that will add a testOutputDirectory parameter instead. Oh, I coded the patch against the 2.7 releases sources.
          Hide
          Andrea Aime added a comment -

          Doh, I should have tested the patch a bit, the .classpath file looked good but the result is that the per entry output are nested with the default output and Eclipse does not like the result.
          Will work on a better solution.

          Show
          Andrea Aime added a comment - Doh, I should have tested the patch a bit, the .classpath file looked good but the result is that the per entry output are nested with the default output and Eclipse does not like the result. Will work on a better solution.
          Hide
          Andrea Aime added a comment - - edited

          Ok, second attempt (testOutputDirectory.patch), this time tested with the GeoTools and GeoServer projects. Seems to work fine there. It would be nice to get confirmation from other people affected by this issue.

          In this one I've added an explicit testOutputDirectory configuration option. It defaults to the project one, and can be overridden like this:

               <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-eclipse-plugin</artifactId>
                  <configuration>
                    <outputDirectory>bin/classes</outputDirectory>
                    <testOutputDirectory>bin/test-classes</testOutputDirectory>
                  </configuration>
                </plugin>
          

          If the developers think this patch is good for inclusion I'll extend it to the documentation as well.

          Show
          Andrea Aime added a comment - - edited Ok, second attempt (testOutputDirectory.patch), this time tested with the GeoTools and GeoServer projects. Seems to work fine there. It would be nice to get confirmation from other people affected by this issue. In this one I've added an explicit testOutputDirectory configuration option. It defaults to the project one, and can be overridden like this: <plugin> <groupId> org.apache.maven.plugins </groupId> <artifactId> maven-eclipse-plugin </artifactId> <configuration> <outputDirectory> bin/classes </outputDirectory> <testOutputDirectory> bin/test-classes </testOutputDirectory> </configuration> </plugin> If the developers think this patch is good for inclusion I'll extend it to the documentation as well.
          Hide
          Hannu Leinonen added a comment -

          I also have an issue (and a patch) related to this. I included a fakeBuildOutputDirectory variable to the plugin which means that it sets the default output folder, but uses the specific output folders for the source directories. This is essential for the Google Plugin for Eclipse development, since it requires certain path for the default output directory. Otherwise I can't run tests or use the Eclipse Java compiler. I'm hosting the patched snapshot (with another patch of mine from http://jira.codehaus.org/browse/MECLIPSE-402) in a Maven repository at http://beardedgeeks.googlecode.com/svn/repository/snapshots/

          Show
          Hannu Leinonen added a comment - I also have an issue (and a patch) related to this. I included a fakeBuildOutputDirectory variable to the plugin which means that it sets the default output folder, but uses the specific output folders for the source directories. This is essential for the Google Plugin for Eclipse development, since it requires certain path for the default output directory. Otherwise I can't run tests or use the Eclipse Java compiler. I'm hosting the patched snapshot (with another patch of mine from http://jira.codehaus.org/browse/MECLIPSE-402 ) in a Maven repository at http://beardedgeeks.googlecode.com/svn/repository/snapshots/
          Hide
          Michael Osipov added a comment -

          Please refer to https://cwiki.apache.org/confluence/display/MAVEN/The+Great+JIRA+Cleanup+of+2014 if you're wondering why this issue was closed out.

          Show
          Michael Osipov added a comment - Please refer to https://cwiki.apache.org/confluence/display/MAVEN/The+Great+JIRA+Cleanup+of+2014 if you're wondering why this issue was closed out.

            People

            • Assignee:
              Unassigned
              Reporter:
              Mark Hobson
            • Votes:
              10 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: