Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-504

own classes and test-classes at the end of test classpath

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.4
    • None
    • Maven Surefire Plugin
    • None
    • Maven 2.0.9, Windows XP

    Description

      Own classes and test-classes may be added to the end of the classpath:

      [DEBUG] Adding to surefire test classpath:
      s:\mavenrepo\org\apache\maven\surefire\surefire-api\2.4\surefire-api-2.4.jar
      [DEBUG] Test Classpath :
      [DEBUG] s:\mavenrepo\log4j\log4j\1.2.13\log4j-1.2.13.jar
      ...
      [DEBUG] s:\mavenrepo\org\apache\xmlsec\1.4.1\xmlsec-1.4.1.jar
      [DEBUG] S:\pdv_cms\GDCAMS\src\pip\gdcams-pip-itest\target\classes
      [DEBUG] S:\pdv_cms\GDCAMS\src\pip\gdcams-pip-itest\target\test-classes

      This may happen, when you add the following terms to a parent pom.xml:

      <properties>
      <target.dir>target</target.dir>
      </properties>

      <build>
      ....
      <!-- special (output)Directory for Eclipse -->
      <!-- see
      http://docs.codehaus.org/display/M2ECLIPSE/Project+FAQ#ProjectFAQ-HowtoconfigureMavenprojecttouseseparateoutputfoldersinEclipse--
      >

      <outputDirectory>${project.basedir}/${target.dir}/classes</outputDirectory>

      <testOutputDirectory>${project.basedir}/${target.dir}/test-classes</testOutputDirectory>

      ....
      </build>

      <profiles>
      <profile>
      <id>eclipse-folders</id>
      <properties>
      <target.dir>target-eclipse</target.dir>
      </properties>
      </profile>
      </profiles>

      The reason for that is:

      SurefirePlugin#constructSurefireBooter changes the classpath by doing:

      ...
      getLog().debug( "Test Classpath :" );

      // Check if we need to add configured classes/test classes directories here.
      // If they are configured, we should remove the default to avoid conflicts.
      if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )

      { classpathElements.remove( project.getBuild().getOutputDirectory() ); classpathElements.add( classesDirectory.getAbsolutePath() ); }

      if ( !project.getBuild().getTestOutputDirectory().equals( testClassesDirectory.getAbsolutePath() ) )

      { classpathElements.remove( project.getBuild().getTestOutputDirectory() ); classpathElements.add( testClassesDirectory.getAbsolutePath() ); }

      ...

      project.getBuild().getOutputDirectory() is like "${basedir}/target/classes"
      classesDirectory.getAbsolutePath() is: "${basedir}\target\classes"

      So i think here a 2 bugs:

      (1) files/directories shouldn´t be compared just as String.equals(....) - using File.compareTo may be a better solution
      (2) an Element of classpathElements shouldn´t be removed and added to the end of the ArrayList, it should be replaced at the same position.

      Attachments

        Issue Links

          Activity

            People

              pgier Paul Gier
              reinhart Torsten Reinhard
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: