Mojo's Exec Maven Plugin
  1. Mojo's Exec Maven Plugin
  2. MEXEC-91

exec:java causes mvn compile to look for test-jar dependencies

    Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None
    • Environment:
      Mac OS X, maven 2 and 3
    • Number of attachments :
      2

      Description

      There is a bad interaction between the exec:java plugin and test-jar dependencies in a multi-module project. In short, if you attach exec:java to an execution phase, "mvn compile" then looks for "test-jar" dependencies even though it should only be looking for compile time dependencies.

      Here is the setup:

      /pom.xml
      /cleartk-token/pom.xml
      /cleartk-token/src/main/java/Token.java
      /cleartk-token/src/test/java/TokenTest.java
      /cleartk-named-entity/pom.xml

      The cleartk-token module uses the "maven-jar-plugin" to package a "test-jar" dependency.

      The cleartk-named-entity module depends on the cleartk-token "jar" dependency at compile time and (additionally) the cleartk-token "test-jar" dependency at test-compile time.

      The cleartk-named-entity module uses exec:java to generate some code in the process-resources phase. (It doesn't actually call any main class in the attached file, but that doesn't seem to be necessary to provoke the bug.)

      Given this setup, if you run "mvn compile" from the top level, with maven 2 you'll get the error:

      [INFO] ------------------------------------------------------------------------
      [ERROR] BUILD ERROR
      [INFO] ------------------------------------------------------------------------
      [INFO] Failed to resolve artifact.

      Missing:
      ----------
      1) org.cleartk:cleartk-token:test-jar:tests:0.7.0-SNAPSHOT

      And with maven 3 you'll get the error:

      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD FAILURE
      [INFO] ------------------------------------------------------------------------
      ...
      [ERROR] Failed to execute goal on project cleartk-named-entity: Could not resolve dependencies for project org.cleartk:cleartk-named-entity:jar:0.1.0-SNAPSHOT: Could not find artifact org.cleartk:cleartk-token:jar:tests:0.7.0-SNAPSHOT

      Now this seems wrong in both cases - at compile time, maven shouldn't be looking for test jars.

      I believe this is an exec:java bug (or at least exec:java revealing a compiler plugin bug) because if I comment out the <executions> element for the "maven-exec-plugin", then everything compiles fine.

      My current workaround is to use "mvn compile package" which I guess makes the "test-jar" dependency visible at compile time. But since the "test-jar" dependency is a test-compile time dependency, I think this shouldn't be necessary.

      1. mvn-compile-bug.tgz
        1 kB
        Steven Bethard
      2. mvn-compile-bug.tgz
        1 kB
        Steven Bethard

        Activity

        Hide
        Steven Bethard added a comment -

        Looks like this problem is bigger than just the exec plugin. Here's an even simpler setup that provokes the error:

        /pom.xml
        /module-with-test-jar/pom.xml
        /module-needing-test-jar/pom.xml

        If you use maven 3 to run:

        mvn compile
        

        You'll get the error:

        [ERROR] Failed to execute goal on project module-needing-test-jar: Could not resolve dependencies for project bug:module-needing-test-jar:jar:0.0.1-SNAPSHOT: Could not find artifact bug:module-with-test-jar:jar:tests:0.0.1-SNAPSHOT

        Which is wrong because you're in the compile phase and maven should not be looking for test scoped dependencies.

        The key points are that the parent has two modules:

        <modules>
          <module>module-with-test-jar</module>
          <module>module-needing-test-jar</module>
        </modules>
        

        The first module supplies the test jar:

        <build>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <executions>
                <execution>
                  <goals>
                    <goal>test-jar</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
        

        And the second module both depends on the test jar, and adds something to the compile phase (or earlier) using an <execution>:

        <dependencies>
          <dependency>
            <groupId>bug</groupId>
            <artifactId>module-with-test-jar</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>test-jar</type>
            <scope>test</scope>
          </dependency>
        </dependencies>
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-surefire-plugin</artifactId>
              <executions>
                <execution>
                  <phase>compile</phase>
                  <goals>
                    <goal>test</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
        

        Here I'm using maven-surefire-plugin to prove that it's not just the maven-exec-plugin that has this problem. In the attached code there's also a commented out section using the maven-exec-plugin that will provoke exactly the same bug.

        Again, a workaround is to run mvn compile test-compile.

        Show
        Steven Bethard added a comment - Looks like this problem is bigger than just the exec plugin. Here's an even simpler setup that provokes the error: /pom.xml /module-with-test-jar/pom.xml /module-needing-test-jar/pom.xml If you use maven 3 to run: mvn compile You'll get the error: [ERROR] Failed to execute goal on project module-needing-test-jar: Could not resolve dependencies for project bug:module-needing-test-jar:jar:0.0.1-SNAPSHOT: Could not find artifact bug:module-with-test-jar:jar:tests:0.0.1-SNAPSHOT Which is wrong because you're in the compile phase and maven should not be looking for test scoped dependencies. The key points are that the parent has two modules: <modules> <module> module-with-test-jar </module> <module> module-needing-test-jar </module> </modules> The first module supplies the test jar: <build> <plugins> <plugin> <groupId> org.apache.maven.plugins </groupId> <artifactId> maven-jar-plugin </artifactId> <executions> <execution> <goals> <goal> test-jar </goal> </goals> </execution> </executions> </plugin> </plugins> </build> And the second module both depends on the test jar, and adds something to the compile phase (or earlier) using an <execution> : <dependencies> <dependency> <groupId> bug </groupId> <artifactId> module-with-test-jar </artifactId> <version> 0.0.1-SNAPSHOT </version> <type> test-jar </type> <scope> test </scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId> maven-surefire-plugin </artifactId> <executions> <execution> <phase> compile </phase> <goals> <goal> test </goal> </goals> </execution> </executions> </plugin> </plugins> </build> Here I'm using maven-surefire-plugin to prove that it's not just the maven-exec-plugin that has this problem. In the attached code there's also a commented out section using the maven-exec-plugin that will provoke exactly the same bug. Again, a workaround is to run mvn compile test-compile .
        Hide
        Benjamin Bentmann added a comment -

        Which is wrong because you're in the compile phase and maven should not be looking for test scoped dependencies.

        Your last example binds surefire:test to the compile phase so as per your configuration, test scoped dependencies are required to run Surefire.

        Back to the original issue, the need for exec:java to resolve test scoped dependencies is documented but there's surely room for improvement to only resolve dependencies that are actually required as per the classpathScope parameter.

        Show
        Benjamin Bentmann added a comment - Which is wrong because you're in the compile phase and maven should not be looking for test scoped dependencies. Your last example binds surefire:test to the compile phase so as per your configuration, test scoped dependencies are required to run Surefire. Back to the original issue, the need for exec:java to resolve test scoped dependencies is documented but there's surely room for improvement to only resolve dependencies that are actually required as per the classpathScope parameter.
        Hide
        Benjamin Bentmann added a comment -

        Again, a workaround is to run mvn compile test-compile.

        Forgot to mentiond, "mvn test-compile" should do as well unless you intentionally need to run the compile phase twice.

        Show
        Benjamin Bentmann added a comment - Again, a workaround is to run mvn compile test-compile. Forgot to mentiond, "mvn test-compile" should do as well unless you intentionally need to run the compile phase twice.
        Hide
        Steven Bethard added a comment -

        the need for exec:java to resolve test scoped dependencies is documented

        Yeah I guess it is. It's easy to find once you know what you're looking for.

        Attributes:

        • Requires a Maven 2.0 project to be executed.
        • Requires dependency resolution of artifacts in scope: test.

        http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html

        Out of curiosity, why does it require that? I guess it's clear to me why surefire:test would require test dependencies, but not why exec:java would.

        Anyway, please consider changing this to a feature request (I don't seem to be able to do that myself). Thanks!

        Show
        Steven Bethard added a comment - the need for exec:java to resolve test scoped dependencies is documented Yeah I guess it is. It's easy to find once you know what you're looking for. Attributes: Requires a Maven 2.0 project to be executed. Requires dependency resolution of artifacts in scope: test. http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html Out of curiosity, why does it require that? I guess it's clear to me why surefire:test would require test dependencies, but not why exec:java would. Anyway, please consider changing this to a feature request (I don't seem to be able to do that myself). Thanks!
        Hide
        Nicholas Williams added a comment -

        Is there any update on this? It has been a year since anyone said anything about it. I have what I thought was a simple project structure, but I cannot get it to build:

        core
        licensor-base depends on core:jar (compile) and core:test-jar (test)
        licensor-ui-core depends on core:jar (compile), licensor-base:jar (compile) and core:test-jar (test)
        licensor-ui-cli depends on core:jar (compile), licensor-base:jar (compile), licensor-ui-core:jar (compile) and core:test-jar (test)
        licensor-ui-desktop depends on core:jar (compile), licensor-base:jar (compile), licensor-ui-core:jar (compile) and core:test-jar (test)

        [ERROR] Failed to execute goal on project licensor-base: Could not resolve dependencies for project net.nicholaswilliams.java.licensing:licensor-base:jar:1.1.0-SNAPSHOT: Could not find artifact net.nicholaswilliams.java.licensing:core:jar:tests:1.1.0-SNAPSHOT -> [Help 1]

        I have tried the following executions:

        Original:

        mvn package javadoc:aggregate-jar assembly:single checksum:files

        Added to original:

        mvn test-compile package javadoc:aggregate-jar assembly:single checksum:files

        Tried simpler (skip Javadoc, assembly, checksum):

        mvn test-compile package

        Tried compile only:

        mvn test-compile

        Only the last one worked. But this is useless, because I need to test, package, document, assemble and checksum my projects.

        IMO, this is NOT a feature request, it is a serious bug.

        Can somebody provide some insight? Is there some workaround I have not tried yet?

        Show
        Nicholas Williams added a comment - Is there any update on this? It has been a year since anyone said anything about it. I have what I thought was a simple project structure, but I cannot get it to build: core licensor-base depends on core:jar (compile) and core:test-jar (test) licensor-ui-core depends on core:jar (compile), licensor-base:jar (compile) and core:test-jar (test) licensor-ui-cli depends on core:jar (compile), licensor-base:jar (compile), licensor-ui-core:jar (compile) and core:test-jar (test) licensor-ui-desktop depends on core:jar (compile), licensor-base:jar (compile), licensor-ui-core:jar (compile) and core:test-jar (test) [ERROR] Failed to execute goal on project licensor-base: Could not resolve dependencies for project net.nicholaswilliams.java.licensing:licensor-base:jar:1.1.0-SNAPSHOT: Could not find artifact net.nicholaswilliams.java.licensing:core:jar:tests:1.1.0-SNAPSHOT -> [Help 1] I have tried the following executions: Original: mvn package javadoc:aggregate-jar assembly:single checksum:files Added to original: mvn test-compile package javadoc:aggregate-jar assembly:single checksum:files Tried simpler (skip Javadoc, assembly, checksum): mvn test-compile package Tried compile only: mvn test-compile Only the last one worked. But this is useless, because I need to test, package, document, assemble and checksum my projects. IMO, this is NOT a feature request, it is a serious bug. Can somebody provide some insight? Is there some workaround I have not tried yet?
        Hide
        Robert Scholte added a comment -

        I think there's some confusion here. I've had a look at the attachment and it doesn't even use the exec-maven-plugin. I think you're referring to MNG-3559.

        Show
        Robert Scholte added a comment - I think there's some confusion here. I've had a look at the attachment and it doesn't even use the exec-maven-plugin. I think you're referring to MNG-3559 .
        Hide
        Nicholas Williams added a comment -

        Didn't someone earlier comment that it's not just maven-exec-plugin, but also maven-surefire-plugin, that triggers this issue? My project uses maven-surefire-plugin.

        Perhaps this bug is in the wrong place. Perhaps it should be in the Maven proper project.

        Or perhaps this bug and MNG-3559 are one and the same? (Speaking of which, if a patch was provided for MNG-3559 five years ago, why has it not been fixed yet!?)

        Show
        Nicholas Williams added a comment - Didn't someone earlier comment that it's not just maven-exec-plugin, but also maven-surefire-plugin, that triggers this issue? My project uses maven-surefire-plugin. Perhaps this bug is in the wrong place. Perhaps it should be in the Maven proper project. Or perhaps this bug and MNG-3559 are one and the same? (Speaking of which, if a patch was provided for MNG-3559 five years ago, why has it not been fixed yet!?)

          People

          • Assignee:
            Unassigned
            Reporter:
            Steven Bethard
          • Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: