Maven Surefire

Have the abiltiy to remove a dependency from the test classpath (at least optional ones

Details

  • Complexity:
    Intermediate
  • Number of attachments :
    0

Issue Links

Activity

Hide
Hardy Ferentschik added a comment -

Forgot to describe a usecase. Say you are developing a library and you have an optional dependency to another library. Depending on whether this optional library is used at runtime your own library behaves differently. In this scenario I would like to have two test sets. One where the tests are run with the optional dependency on the classpath and one without. It is already possible two configure two executions of the surefire plugin, but I cannot remove a dependency. Basically optional dependencies should be removable via some excludes configuration.

Show
Hardy Ferentschik added a comment - Forgot to describe a usecase. Say you are developing a library and you have an optional dependency to another library. Depending on whether this optional library is used at runtime your own library behaves differently. In this scenario I would like to have two test sets. One where the tests are run with the optional dependency on the classpath and one without. It is already possible two configure two executions of the surefire plugin, but I cannot remove a dependency. Basically optional dependencies should be removable via some excludes configuration.
Hide
Hardy Ferentschik added a comment -

BTW, I know that I can get it working to a certain degree unsing profiles, but the resulting pom just looks terrible.

Show
Hardy Ferentschik added a comment - BTW, I know that I can get it working to a certain degree unsing profiles, but the resulting pom just looks terrible.
Hide
Paul Gier added a comment -

Fixed in r945404.

Show
Paul Gier added a comment - Fixed in r945404.
Hide
Hardy Ferentschik added a comment -

Cool. What's the timeline for 2.6? Or is there a SNAPSHOT I could try?

Show
Hardy Ferentschik added a comment - Cool. What's the timeline for 2.6? Or is there a SNAPSHOT I could try?
Hide
Paul Gier added a comment -

I deployed a new snapshot to the snapshots repository (https://repository.apache.org/content/repositories/snapshots/)

Show
Paul Gier added a comment - I deployed a new snapshot to the snapshots repository (https://repository.apache.org/content/repositories/snapshots/)
Hide
A added a comment - - edited

Hello,

I've tested the changes today. It seems like the filter is actually including what user chooses in the exclude elements.

private Set filterArtifacts( Set artifacts, ArtifactFilter filter )
    {
        Set filteredArtifacts = new LinkedHashSet();

        for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
        {
            Artifact artifact = (Artifact) iter.next();
            if ( filter.include( artifact ) )
            {
                filteredArtifacts.add( artifact );
            }
        }

        return filteredArtifacts;
    }

Perhaps you intended it as "if ( ! filter.include( artifact ) )"?

Another glitch I'm seeing is that description of the scope excludes element is misleading. compile+runtime doesn't seem to be recognized as a valid option for filtering but "runtime" alone is what works for me. Also I can't make "runtime+system" working neither "system". I've no why.

Thanks!

Show
A added a comment - - edited Hello, I've tested the changes today. It seems like the filter is actually including what user chooses in the exclude elements.
private Set filterArtifacts( Set artifacts, ArtifactFilter filter )
    {
        Set filteredArtifacts = new LinkedHashSet();

        for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
        {
            Artifact artifact = (Artifact) iter.next();
            if ( filter.include( artifact ) )
            {
                filteredArtifacts.add( artifact );
            }
        }

        return filteredArtifacts;
    }
Perhaps you intended it as "if ( ! filter.include( artifact ) )"? Another glitch I'm seeing is that description of the scope excludes element is misleading. compile+runtime doesn't seem to be recognized as a valid option for filtering but "runtime" alone is what works for me. Also I can't make "runtime+system" working neither "system". I've no why. Thanks!
Hide
A added a comment - - edited

Actually I see the issue better now. For scope ExcludesArtifactFilter is used and for individual artifacts ExcludesArtifactFilter is used so it seems either a new method needs to be created or ExcludesArtifactFilter changed to IncludesArtifactFilter and filterArtifacts() to reflect that.

For the second issue with scope names I tried using maven 2.2.1 but still I can't make a system artifact to be excluded.

Show
A added a comment - - edited Actually I see the issue better now. For scope ExcludesArtifactFilter is used and for individual artifacts ExcludesArtifactFilter is used so it seems either a new method needs to be created or ExcludesArtifactFilter changed to IncludesArtifactFilter and filterArtifacts() to reflect that. For the second issue with scope names I tried using maven 2.2.1 but still I can't make a system artifact to be excluded.
Hide
Paul Gier added a comment -

Thanks for testing this. You're right my logic was correct for the individual dependency excludes but reversed for the scope excludes. The missing combined scopes is probably because surefire is using an older version of the scope filter, so I'll update this also.

Show
Paul Gier added a comment - Thanks for testing this. You're right my logic was correct for the individual dependency excludes but reversed for the scope excludes. The missing combined scopes is probably because surefire is using an older version of the scope filter, so I'll update this also.
Hide
Paul Gier added a comment -

Another update in r946778

Show
Paul Gier added a comment - Another update in r946778
Hide
A added a comment -

I've tested the new commit. It appears to be working for my purposes - testing a packaged for distribution product rather than the project compiled classes. Thank you for implementing this feature!

I'm putting below a sample configuration just for a reference. I see that system dependencies can be excluded either by the "test" scope or with their group and artifact id. Also the build classes can be excluded by configuring a fake location for them and although looking hacky, this method seems reasonable to me.

<profile>
      <id>product-test</id>
      <activation>
         <activeByDefault>false</activeByDefault>
      </activation>
      <build>
         <plugins>
            <plugin>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.6-SNAPSHOT</version>
               <configuration>
                  <classesDirectory>fakeClassesDirectory</classesDirectory>
                  <!-- testClassesDirectory>fakeTestClassesDirectory</testClassesDirectory -->
                  <classpathDependencyScopeExclude>runtime</classpathDependencyScopeExclude>
                  <classpathDependencyExcludes>
                     <exclude>org.apache.commons:*</exclude>
                     <exclude>testGrp:testId</exclude>
                  </classpathDependencyExcludes>
                  <additionalClasspathElements>
                     <additionalClasspathElement>/path/to/product/installation/artifact1.jar</additionalClasspathElement>
                     <additionalClasspathElement>/path/to/product/installation/artifact2.jar</additionalClasspathElement>
                  </additionalClasspathElements>
               </configuration>
            </plugin>
         </plugins>
      </build>
    </profile>

Then tester should look at the mvn -Pproduct-test -X output (search for "Test Classpath")to verify classpath is what's expected. btw it will become more convenient once MNG-2570 is resolved and debug logging only from the SurefirePlugin class can be enabled through CLI rather than full debug of everything.

Show
A added a comment - I've tested the new commit. It appears to be working for my purposes - testing a packaged for distribution product rather than the project compiled classes. Thank you for implementing this feature! I'm putting below a sample configuration just for a reference. I see that system dependencies can be excluded either by the "test" scope or with their group and artifact id. Also the build classes can be excluded by configuring a fake location for them and although looking hacky, this method seems reasonable to me.
<profile>
      <id>product-test</id>
      <activation>
         <activeByDefault>false</activeByDefault>
      </activation>
      <build>
         <plugins>
            <plugin>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.6-SNAPSHOT</version>
               <configuration>
                  <classesDirectory>fakeClassesDirectory</classesDirectory>
                  <!-- testClassesDirectory>fakeTestClassesDirectory</testClassesDirectory -->
                  <classpathDependencyScopeExclude>runtime</classpathDependencyScopeExclude>
                  <classpathDependencyExcludes>
                     <exclude>org.apache.commons:*</exclude>
                     <exclude>testGrp:testId</exclude>
                  </classpathDependencyExcludes>
                  <additionalClasspathElements>
                     <additionalClasspathElement>/path/to/product/installation/artifact1.jar</additionalClasspathElement>
                     <additionalClasspathElement>/path/to/product/installation/artifact2.jar</additionalClasspathElement>
                  </additionalClasspathElements>
               </configuration>
            </plugin>
         </plugins>
      </build>
    </profile>
Then tester should look at the mvn -Pproduct-test -X output (search for "Test Classpath")to verify classpath is what's expected. btw it will become more convenient once MNG-2570 is resolved and debug logging only from the SurefirePlugin class can be enabled through CLI rather than full debug of everything.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: