mavendependency-managementspring-cloud-contract

maven-dependency-plugin reports unused dependencies only when run without clean


The checks pass when I run clean verify.

[INFO] --- dependency:3.8.1:analyze-only (analyze-only) @ server ---
[INFO] No dependency problems found

But they fail when I then run just verify.

dependency:3.8.1:analyze-only (analyze-only) @ server ---
[ERROR] Unused declared dependencies found:
[ERROR]    org.springframework.cloud:spring-cloud-contract-verifier:jar:4.1.4:test
[ERROR]    com.toomuchcoding.jsonassert:jsonassert:jar:0.8.0:test
[ERROR]    com.jayway.jsonpath:json-path:jar:2.9.0:test
[ERROR]    org.assertj:assertj-core:jar:3.24.2:test

I'm not sure how an un-clean build would cause unused dependencies to appear.

Since those are all test dependencies the Spring Cloud Contract is the most likely culprit. Maybe on repeated run it doesn't add a source directory to the build?


Solution

  • Adding this makes the build result stable - I get a pass on the dependency check in both cases.

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>add-test-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>target/generated-test-sources/contracts</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    

    I've reported this: https://github.com/spring-cloud/spring-cloud-contract/issues/2144