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

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

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2.1, 3.3.1, 3.3.9
    • Fix Version/s: 3.8.2, 4.0.0, 4.0.0-alpha-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      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

            • Assignee:
              slachiewicz Sylwester Lachiewicz
              Reporter:
              mpsabe Alexander Bender

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

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

                  Issue deployment