[ 
https://issues.apache.org/jira/browse/MNG-6442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16591645#comment-16591645
 ] 

Robert Scholte commented on MNG-6442:
-------------------------------------

I don't agree with you: you want to test a jar, so in a Maven world that should 
be a dependency in a separate project. You're trying to abuse the 
build-lifecycle to do testing without building. The surefire plugin fits very 
well in the build-lifecycle, but not in this testing lifecycle you have in 
mind. This is one of those examples where you are fighting Maven, which should 
be a sign to wonder if you are on the right path.

If you really really want to solve this within 1 project, (I hate to say this) 
think of profiles. But this will imply a couple of tricks with plugins, which 
will make it really clumsy. My proposal with the 2 modules will at least keep 
the poms clean.

 

> Run tests with Maven on pre-compiled project
> --------------------------------------------
>
>                 Key: MNG-6442
>                 URL: https://issues.apache.org/jira/browse/MNG-6442
>             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 
> (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...
> Regards,
> Lasse
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to