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

Enable custom JAR and resource loading in Surefire classpath

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 2.4.3
    • None
    • classloading
    • None
    • any
    • Patch

    Description

      There are situations in which you would want to add to surefire classpath an arbitrary resourceSet to have your tests running properly.

      To clarify, there are cases in which maven transitive dependency management cannot be enough for having your classpath populated properly, cases in which not even the <additionalClasspathElement> of surefire can be enough, unless you pollute your pom with a huge numer of <additionalClasspathElement> lines (tough to write and maintain).

      Maybe an example can clarify the situation:
      if you're working with a legacy Webapp, say a WAR built with Ant, that has no POM, but you want to use Maven features to improve testing and to provide a standard approach to lifecycle management. You'd like be able to test in isolation (outside of a container) against the webapp classpath, but while WEB-INF/classes can be loaded with <additionalClasspathElement>, you'd name each and every JAR in the WEB-INF/lib to have the classpath properly populate.

      This is infact my case when trying to support Alfresco ECM [1] testing with my maven archetypes [2].

      So, after playing around with Java6 classpath wildcard loading [3] (which seems not to be honored by surefire), I wrote this little patch which adds to surefire a new configuration parameter:

      <resources>
      <resource>
      ....
      </resource>
      </resources>

      which allows to load arbitrary resources in the surefire classpath, using the usual directory/include/exclude format supported by the Maven DirectoryScanner. This solves my problems as now I can happily load the Alfresco's WEB-INF/lib/*.jar resourceSet.

      It does not check for duplicates so it's left to the developer to check it the maven transitive classpath clashes with the added resources (as this should be discouraged, I think it should stay like this).

      I understand this should be discouraged, but I could not find a way to work this around (until Alfresco release his POM [4]) in the current surefire setup.

      WDYT? Shall I write a test case or you think is never going to make it to the trunk?

      [1] http://www.alfresco.com/
      [2] http://repository.sourcesense.com/maven2-sites/maven-alfresco-archetypes
      [3] http://www.javabeat.net/qna/90-adding-jars-to-the-classpath/
      [4] https://issues.alfresco.com/jira/browse/ETHREEOH-1090

      Attachments

        1. SurefireResourceLoading.diff
          4 kB
          Gabriele Columbro

        Issue Links

          Activity

            People

              tibordigana Tibor Digana
              g.columbro Gabriele Columbro
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: