Cannot use jacoco JVM args and surefire JVM args together in maven

前端 未结 10 534
深忆病人
深忆病人 2020-11-30 01:48

I am using maven with the jacoco plugin to generate code coverage metrics. I am having some difficulty in configuring the surefire plugin with the java opt

10条回答
  •  无人及你
    2020-11-30 02:19

    I recently ran into the same issue and even took implicitly the same steps as you described with the same result. No clean solution I found worked for me.

    So I ran several steps in debug mode and it seems that Maven replaces properties twice. That is not just in a lazy manner, as I thought, but in both eager and lazy manner:

    1. eagerly (before any goal is run) are replaced static properties (defined in properties section of POM and probably also settings.xml),
    2. lazily (before each execution) are replaced dynamic properties.

    This is where our step with setting a blank property as a default failed. Maven just went:

    1. eager replace of default value (blank)
    2. JaCoCo sets dynamic value
    3. lazy replace of dynamic values (nothing to replace now, already used the blank value)

    Finally the solution is to set the default value dynamically. This can be done with GMaven plugin like this:

    
      org.codehaus.gmaven
      gmaven-plugin
      1.5
      
        
          set-default-values
          initialize
          
            execute
          
          
            
              project.properties.'surefire.argLine' = ''
            
          
        
      
    
    

    So now Maven goes:

    1. eager replace of static properties
    2. GMaven dynamically sets default value (if profile is active)
    3. JaCoCo sets dynamic value
    4. Surefire runs with correctly set argLine

    With active profile the exec file is generated, with non-active profile the blank default value is used and build succeeds.

提交回复
热议问题