Uploaded image for project: 'Maven JAR Plugin'
  1. Maven JAR Plugin
  2. MJAR-138

jar:test-jar is skipped when maven.test.skip=true

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3.1
    • Fix Version/s: more-investigation
    • Component/s: None
    • Labels:
      None
    • Environment:
      jar:test-jar

      Description

      Not sure if this is a bug or improvement...

      Example:

      • ./pom.xml
      • ./moduleA/pom.xml
      • ./moduleB/pom.xml

      Situation:

      • moduleA produces moduleA-1.2.3-test.jar with the jar:test-jar goal
      • moduleB consumes moduleA-1.2.3-test.jar as a <dependency>...<scope>test</scope><dependency>

      Problem:

      • When -Dmaven.test.skip=true the moduleA-1.2.3-test.jar is never built.
      • Then when moduleB tries to build, it's moduleA-1.2.3-test.jar dependency is unresolved. FAIL! Even with -Dmaven.test.skip=true this will fail.

      You might argue that this is a bug with dependency resolution with -Dmaven.test.skip=true - should a missing dependency @ test scope really fail the build??? It probably should - which is why the bug is submitted here

      I've no idea what could be done to fix this either?

      p.s. for anyone with this bug the only workaround I can suggest is running another module...

      ./moduleA-test/pom.xml

      and have <dependency>...<artifactId>moduleA-test<artifactId>...<scope>test</scope></dependency>

        Issue Links

          Activity

          Hide
          bentmann Benjamin Bentmann added a comment -

          maven.test.skip=true suppresses multiple things: test compilation, test execution and test jar packaging. The later was intentionally done as per MJAR-90.

          Independently how this should be addressed in the future, for now a simple workaround is to use skipTests=true instead. This suppresses test execution only, but produces a proper test-jar which allows other modules to both properly resolve their dependencies and even compile against those.

          Show
          bentmann Benjamin Bentmann added a comment - maven.test.skip=true suppresses multiple things: test compilation, test execution and test jar packaging. The later was intentionally done as per MJAR-90 . Independently how this should be addressed in the future, for now a simple workaround is to use skipTests=true instead. This suppresses test execution only, but produces a proper test-jar which allows other modules to both properly resolve their dependencies and even compile against those.
          Hide
          sofiap Sofia Paiva added a comment - - edited

          Hi,

          I have the same problem.

          If i use maven.test.skip=true, the dependency is not found and the build fails. If i use skipTests=true, the jar-test is produced, but integration-tests are executed.

          I agree with Andrew that a test dependency shouldn't fail the build.

          Show
          sofiap Sofia Paiva added a comment - - edited Hi, I have the same problem. If i use maven.test.skip=true , the dependency is not found and the build fails. If i use skipTests=true , the jar-test is produced, but integration-tests are executed. I agree with Andrew that a test dependency shouldn't fail the build.
          Hide
          npapadacis Nath added a comment -

          I do agree that in some situations it should be down to the dependency resolution to skip "test" scope dependencies if we specify maven.test.skip.
          But for now we can utilise the forceCreation configuration setting within the maven-jar-plugin to forcefully create the test-jars even if maven.test.skip is specified by applying the following patch.

          Show
          npapadacis Nath added a comment - I do agree that in some situations it should be down to the dependency resolution to skip "test" scope dependencies if we specify maven.test.skip. But for now we can utilise the forceCreation configuration setting within the maven-jar-plugin to forcefully create the test-jars even if maven.test.skip is specified by applying the following patch.
          Hide
          npapadacis Nath added a comment -

          Patch to allow <forceCreation>true</forceCreation> to create test-jar package even if maven.test.skip = true

          Show
          npapadacis Nath added a comment - Patch to allow <forceCreation>true</forceCreation> to create test-jar package even if maven.test.skip = true
          Hide
          rene.grob Rene Grob added a comment -

          If -Dmaven.test.skip=true skips the test compilation why is maven complaining about missing dependencies that are of scope TEST? There's something wrong with that...

          Show
          rene.grob Rene Grob added a comment - If -Dmaven.test.skip=true skips the test compilation why is maven complaining about missing dependencies that are of scope TEST? There's something wrong with that...
          Hide
          buzzeri Ivan Bondarenko added a comment - - edited

          The same situation (version 2.4) and need the same feature. Nath's patch is Ok for us.

          P.S. Actually setting skip=false is also good as explicit value has a priority.

          Show
          buzzeri Ivan Bondarenko added a comment - - edited The same situation (version 2.4) and need the same feature. Nath's patch is Ok for us. P.S. Actually setting skip=false is also good as explicit value has a priority.
          Hide
          nbardelot Noël BARDELOT added a comment -

          Still an issue up to Maven 3.3.

          In my opinion this is a bug : download of all dependencies using scope "test" should not be triggered when "-Dmaven.test.skip=true" is set.

          Show
          nbardelot Noël BARDELOT added a comment - Still an issue up to Maven 3.3. In my opinion this is a bug : download of all dependencies using scope "test" should not be triggered when "-Dmaven.test.skip=true" is set.
          Hide
          blizzard Bisser Peshev added a comment - - edited

          We just encountered this issue in Maven 3.3.3. Our builds usually take over an hour, so, to save time, the sandbox builds always run with -Dmaven.test.skip=true. But because of this, the test-jar artifacts don't get created, yet each test-jar dependency is enforced (even though it's test-scoped, and even though maven.test.skip is true), so the build breaks.

          I agree with the above comments that this is a bug and should be fixed. If -Dmaven.test.skip=true skips the creation of the test-jar artifact, it should also skip enforcing the dependencies on that test-jar artifact.

          Show
          blizzard Bisser Peshev added a comment - - edited We just encountered this issue in Maven 3.3.3. Our builds usually take over an hour, so, to save time, the sandbox builds always run with -Dmaven.test.skip=true. But because of this, the test-jar artifacts don't get created, yet each test-jar dependency is enforced (even though it's test-scoped, and even though maven.test.skip is true), so the build breaks. I agree with the above comments that this is a bug and should be fixed. If -Dmaven.test.skip=true skips the creation of the test-jar artifact, it should also skip enforcing the dependencies on that test-jar artifact.
          Hide
          khmarbaise Karl Heinz Marbaise added a comment -

          First this is not related to the used Maven version it is related to the used the maven-jar-plugin version. Apart from that yes this is actually the case. You can bypass this by using the following configuration:

            <pluginManagement>
              <plugins>
                <plugin>
                  <artifactId>maven-jar-plugin</artifactId>
                  <version>XXX</version>
                  <configuration>
                    <skip>false</false>
                  </configuration>
                </plugin>
              </plugins>
            </pluginManagement>
          
          Show
          khmarbaise Karl Heinz Marbaise added a comment - First this is not related to the used Maven version it is related to the used the maven-jar-plugin version. Apart from that yes this is actually the case. You can bypass this by using the following configuration: <pluginManagement> <plugins> <plugin> <artifactId> maven-jar-plugin </artifactId> <version> XXX </version> <configuration> <skip> false </false> </configuration> </plugin> </plugins> </pluginManagement>
          Hide
          blizzard Bisser Peshev added a comment - - edited

          Thank you for your response. Unfortunately, after adding the <skip>false</skip> configuration, an empty test-jar was produced when maven.test.skip was true. Or rather, it only contained the manifest file, but no classes. This is not a solution.

          Yes, it's a maven-jar-plugin problem, because it doesn't create the test-jar. But Maven itself also takes part in the problem, because it enforces the dependencies on the test-jar, although they are not needed when maven.test.skip is true. But then again, probably it's not Maven's responsibility to decide which dependency is needed and which isn't, neither is it supposed to know about the maven.test.skip option.

          I suppose the simplest solution would be for maven-jar-plugin to stop checking the value of maven.test.skip and let the surefire plugin worry about that option. So, maven-jar-plugin will always generate the test-jar.

          Show
          blizzard Bisser Peshev added a comment - - edited Thank you for your response. Unfortunately, after adding the <skip>false</skip> configuration, an empty test-jar was produced when maven.test.skip was true. Or rather, it only contained the manifest file, but no classes. This is not a solution. Yes, it's a maven-jar-plugin problem, because it doesn't create the test-jar. But Maven itself also takes part in the problem, because it enforces the dependencies on the test-jar, although they are not needed when maven.test.skip is true. But then again, probably it's not Maven's responsibility to decide which dependency is needed and which isn't, neither is it supposed to know about the maven.test.skip option. I suppose the simplest solution would be for maven-jar-plugin to stop checking the value of maven.test.skip and let the surefire plugin worry about that option. So, maven-jar-plugin will always generate the test-jar.
          Hide
          blizzard Bisser Peshev added a comment -

          Well, there's a workaround with Maven profiles. The test-jar dependencies will be declared only if maven.test.skip is not true:

                <profile>
                   <activation>
                      <property>
                         <name>maven.test.skip</name>
                         <value>!true</value>
                      </property>
                   </activation>
                   <dependencies>
                      <dependency>
                         <groupId>com.acme.project</groupId>
                         <artifactId>my-artifact</artifactId>
                         <type>test-jar</type>
                         <version>${project.version}</version>
                         <scope>test</scope>
                      </dependency>
                   </dependencies>
                </profile>
          

          Ugly, but at least works.

          Show
          blizzard Bisser Peshev added a comment - Well, there's a workaround with Maven profiles. The test-jar dependencies will be declared only if maven.test.skip is not true: <profile> <activation> <property> <name> maven.test.skip </name> <value> !true </value> </property> </activation> <dependencies> <dependency> <groupId> com.acme.project </groupId> <artifactId> my-artifact </artifactId> <type> test-jar </type> <version> ${project.version} </version> <scope> test </scope> </dependency> </dependencies> </profile> Ugly, but at least works.
          Hide
          rfscholte Robert Scholte added a comment -

          There are a couple of plugin "listening" to this property:

          I don't know the complete history of this property, but I can imagine the following: if you don't want to run tests, no need to compile them nor to package them. It is not such a weird idea to have the property cause this as default behavior, but is it correct?

          Show
          rfscholte Robert Scholte added a comment - There are a couple of plugin "listening" to this property: compiler:testCompile skip surefire:test skip jar:test-jar skip I don't know the complete history of this property, but I can imagine the following: if you don't want to run tests, no need to compile them nor to package them. It is not such a weird idea to have the property cause this as default behavior, but is it correct?

            People

            • Assignee:
              Unassigned
              Reporter:
              ahhughes Andrew Hughes
            • Votes:
              14 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

              • Created:
                Updated:

                Development