maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karl Heinz Marbaise (JIRA)" <>
Subject [jira] [Commented] (MNG-6442) Run tests with Maven on pre-compiled project
Date Wed, 01 Aug 2018 07:18:00 GMT


Karl Heinz Marbaise commented on MNG-6442:

After rereading this I have a question: If I re-compiled everywhere I fear I might introduce
errors unwittingly... 

This can simply prevented by using a version control tool ? If you compile always the same
state it's not a problem..for example using Jenkins pipelines building on different nodes
and/or different JDK's? The Maven project is doing it exactly that...Just as an example:
runs on different OS's and different JDK's ? And yes it recompiles the code...

Furthermore running unit tests from a compiled jar/module might not be the correct way cause
in pre JDK9 era that might be ok (Questioning the idea of unit tests?) but starting with Modules
this will not work anymore cause unit tests often access/test internals which are not open
for usage based on {{module-info}}. and for this it is needed to run them before packaging
them into a jar...

> Run tests with Maven on pre-compiled project
> --------------------------------------------
>                 Key: MNG-6442
>                 URL:
>             Project: Maven
>          Issue Type: Wish
>          Components: Artifacts and Repositories, Dependencies
>    Affects Versions: 3.5.2
>         Environment: Linux, Windows
>            Reporter: Lasse Westh-Nielsen
>            Priority: Minor
> Hello,
> 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 (,
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
> _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...
> Regards,
> Lasse

This message was sent by Atlassian JIRA

View raw message