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

Run tests with Maven on pre-compiled project



    • Type: Wish
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.5.2
    • Fix Version/s: None
    • Labels:
    • Environment:
      Linux, Windows



      This is not so much a bug as it is a support request. The mailing list link was out of order. Please do triage into the right category.

      I tried my luck on Stack Overflow (https://stackoverflow.com/questions/51079816/run-tests-with-maven-on-pre-compiled-project), but got nothing, and I really need some direction.

      Here is what I wrote on SO:

      Using Maven, I want to run unit and integration tests on a pre-compiled/ pre-jar'ed multi-module project. I am finding this exceedingly difficult.

      My business case is, I want to compile and jar up a multi-module Maven project in one place, and then have the unit test and integration tests run using different Java versions and on different operating systems, to check for compatibility. Let's just say {Java 8, Java 10} x {Ubuntu, Windows} to keep it simple.

      The reason I want to compile and jar up in one pace is, I want to ensure that I run tests on the actual code getting shipped. If I re-compiled everywhere I fear I might introduce errors unwittingly.

      One solution is to do mvn deploy -DaltDeploymentRepository=$mydir on Ubuntu to produce a compiled project tree and a directory full of jars; then zipping up the project tree and deploy directory and shipping them off to a Windows machine; and there running mvn surefire:test -Dmaven.repo.local=$mydir on the project tree.

      That works but it is hella clumsy. Surefire seems to read the test classes in the project tree and use the classes in the same project + jar dependencies from the deployment repo to link against. A problem there is, with -Dmaven.repo.local Maven needs to download all 3rd party dependencies again because that repo only contains my project artifacts. So a solid solution, but not great.

      Instead what I have been trying to do is, just use the compiled project tree:

      • If I just do mvn surefire:test I get problems resolving dependencies
      • I have tried mvn compile -Dmaven.main.skip surefire:test to fix dependency resolution, which seems to work - just not for test dependencies
      • I further tried mvn compile -Dmaven.main.skip test-compile -Dmaven.test.skip surefire:test, but for some reason that also does not work, the build again fails trying to resolve test dependencies.

      Interestingly, it is not deterministic, the failures happen at different stages and sometimes not at all - I get the occasional green build!

      And now I am at my wits' end: I keep thinking this should be simple, and that I can't possible be the first person struggling with this simple problem.

      It is opaque to me what happens with the reactor, when and how it triggers. The dependency graph must have been well-formed, or it couldn't compile. So why can I not get Maven to reproduce the same dependency graph for running tests?

      Further to that:

      • I tried installing artifacts in cache using `mvn install:install`, that didn't work
      • I tried `mvn install` but was unable to get it to not re-compile and re-jar my artifacts
      • I have tried simply copying files as a way to install my artifacts on machines

      Current status is, copying files manually to ~/.m2/repository is most promising, it seems to work on Linux. However, it does not work on Windows, I'm still trying to figure out why - line endings perhaps, the artifacts come from a Linux machine. The problem is artifact lookup.

      Anyway, going back to first principles: what's the recommended way to achieve running tests with Maven on pre-compiled project? I'm hoping someone has solved this before...







            • Assignee:
              lassewesth Lasse Westh-Nielsen
            • Votes:
              0 Vote for this issue
              3 Start watching this issue


              • Created: