문제

I have a multi-module project. I'm using as my IDE. I have Maven configured with the plugin to automatically instrument on build. How can I get IntelliJ to recognize those changes and refresh its coverage data.(NOTE: having to click the "Refresh Coverage" toolbar button is fine.)

I've tried configuring maven-clover2-plugin like so:

  <plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-clover2-plugin</artifactId>
    <version>3.2.2</version>
    <configuration>
      <baseDir>${project.basedir}</baseDir>
      <cloverMergeDatabase>
        ${project.basedir}.clover\cloverMerge.db
      </cloverMergeDatabase>
    </configuration>
    <executions>
      <execution>
        <id>main</id>
        <phase>package</phase>
        <goals>
          <goal>instrument</goal>
          <goal>aggregate</goal>
          <goal>check</goal>
        </goals>
      </execution>
      <execution>
        <id>site</id>
        <phase>pre-site</phase>
        <goals>
          <goal>instrument</goal>
          <goal>aggregate</goal>
          <goal>check</goal>
        </goals>
      </execution>
      <execution>
        <id>clean</id>
        <phase>clean</phase>
        <goals><goal>clean</goal></goals>
      </execution>
    </executions>
  </plugin>

I then configured my project settings to use:
.clover\cloverMerge.db and checked the relative to project directory. checkbox.

But that didn't work.

NOTE:
At the bottom of Configuring Instrumentation it says
Do not set these locations explicitly if you have a multi-module project.
So I also tried leaving the location as the default for both Maven and IDEA and that didn't work either.

Also in the Clover for IDEA installation GUIDE - Known Issues

If you are using the Maven build tool, you should avoid using the same > IntelliJ output directory as Maven does. As Maven uses the target/classes and target/test-classes directories,
avoid specifying these ones. The clover.db location for IntelliJ should also be distinct from that used by Maven.

WHY should they be distinct is there some file corruption issue? If they're kept distinct then HOW can I get awesome coverage highlighting/etc, without having to repeat builds in a completely separate process?

도움이 되었습니까?

해결책

Well I finally figured out an answer. I'm leaving this here for posterity.

The solution is complicated and somewhat of a Hack but it WORKS.

  1. Update the parent projects pom.xml file

    • cloverDB: <cloverDatabase>${project.basedir}.clover\clover.db</cloverDatabase>
    • Merge CloverDB:
      <cloverMergeDatabase> ${project.basedir}.clover\cloverMerge.db </cloverMergeDatabase>
  2. Create your Unit Tests to Run in IntelliJ IDEA

    • setup a Before launch - Run Maven Goal
      clean clover2:setup prepare-package -DSkipTests
      Run Configuration for Unit tests screen
  3. Create a Maven Run Configuration
    • Make the Unit-Tests a Before launch condition
    • In the command line have Maven run clover2:aggregrate
      Run Configuration to have Maven Run the tests and aggregate the results
  4. Update Intellij Project Settings for clover to point to the merge file
    • Make sure the Relative to project directory. checkbox is checked.
    • InitString to User specified with the value the same as your pom file.
      in my case: .clover\cloverMergeDB
      Settings Screen with CheckBox Checked and File name
  5. Once the command is run, just click the Referesh Coverage icon to see and work with the coverage data in idea.
    • If the tests fail you will also have the nice IntelliJ Test runner Tab to figure out why.

다른 팁

At the bottom of Configuring Instrumentation it says Do not set these locations explicitly if you have a multi-module project.

Documentation actually says: Do not set these locations explicitly (using absolute path) if you have a multi-module project. The reason is simple - if you use an absolute path, then you will not have a separate clover.db for every module, but only a single clover.db file.

"If you are using the Maven build tool, you should avoid using the same IntelliJ output directory as Maven does. As Maven uses the target/classes and target/test-classes directories, avoid specifying these ones" [...] WHY should they be distinct is there some file corruption issue?

The problem is as follows: IntelliJ IDEA uses it's own engine to compile sources. It means that it does not have to call the original project's build system (a Maven, for instance) to compile sources.

It means that: - if you have a Maven-based project and it has the Clover-for-Maven plugin installed and - at the same time you have the Clover-for-IDEA installed in the IntelliJ IDE - and these two Clover integrations use the same output folders for classes and databases

... then these two Clover integrations may start overwriting their files.

In most cases this is not a desired behaviour because any source code modification / project rebuild action etc in IDEA will trigger source recompilation; which can delete results obtained previously by Clover-for-Maven.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top