Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-6071

GetResource ('/) returns 'null' if build is started with -f

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.2.1, 3.3.1, 3.3.9
    • 3.8.2, 4.0.0-alpha-2, 4.0.0
    • None
    • None
    • Windows 10 x64
      Tested in cmd.exe, git bash.

    Description

      I set up a very simple test maven project with only a dependency to testNG.

          public class TestTest {
          @Test
          public void test() {
              System.out.println(getClass().getResource("/"));
      

      Depending on how I build this, the call either returns null or the expected directory. How is that?

          // Prints: file:/C:/workspace/test/testproject/target/test-classes/
          mvn clean test -Dtest=TestTest -f pom.xml
          // Prints: file:/C:/workspace/test/testproject/target/test-classes/
          mvn clean test -Dtest=TestTest -f testproject/pom.xml
          // Prints: null
          mvn clean test -Dtest=TestTest -f ./pom.xml
          // Prints: null
          mvn clean test -Dtest=TestTest -f ./testproject/pom.xml
      

      Note that the second call includes "./" after -f.

      I actually want to find out the /target folder regardless of scenario (testNG in IntelliJ, Maven, Jenkins Buid, ...). So far, this way has proven the most reliable.

              System.out.println(getClass().getResource("./"));
      

      This seems to reliably point to file:/C:/workspace/test/testproject/target/test-classes/com/testproject/test. Would this be safer to use?

      Attachments

        Issue Links

          Activity

            People

              slachiewicz Sylwester Lachiewicz
              mpsabe Alexander Bender
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m