Spring can't initialize beans with Clover
Symptoms
After enabling Clover, compilation succeeds, but Spring fails to create beans at a runtime with a similar error:
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someBean': Autowiring of fields failed;
...
nested exception is org.springframework.beans.factory.BeanCreationException: Unsatisfied dependency of type [interface com.some.SomeBean]: expected at least 1 matching bean
Application runs correctly if Clover is disabled.
Cause
This might be caused by a fact that implementation for com.some.SomeBean is being generated in your build process. For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy file="${project.build.sourceDirectory}/com/some/SomeBeanImpl.java.gen."
tofile="${project.build.sourceDirectory}/com/some/SomeBeanImpl.java" overwrite="true" />
</target>
</configuration>
</execution>
</executions>
</plugin>
In such case, when you run standard Clover instrumentation, such as:
mvn clean clover:setup test clover:clover clover:aggregate
Clover's code instrumentation (clover:setup) will occur before bean's code generation (as the 'generate-sources' phase will be triggered by the 'test' phase). Clover will also change source roots (e.g. from 'src/main/java' to 'target/clover/src-instrumented'). As a consequence, the SomeBeanImpl.java file will be written to an old source root and will not be compiled at all.
Resolution
Please verify if your build process contains any code/resource generation. If it does, make sure that Clover is initialized and sources are instrumented after all files are have already been generated. You can either do it in a command line:
mvn clean generate-sources clover:setup test
or you can bind the 'clover:setup' to a build phase which happens after the 'generate-sources' one, for example:
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>clover-maven-plugin</artifactId> <!-- Before 4.1.1 it was called maven-clover2-plugin -->
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>setup</goal>
</goals>
</execution>
</executions>
</plugin>