Maven 建议不要使用测试罐,但我最终会产生循环依赖

Maven recommends not using test-jars, yet I would end up with a cyclic dependency

我有 2 个模块,结构如下

目前这很好,因为我的主模块会添加对 lib 的 test-jar 模块的依赖,但是如此处所示 https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html 建议改为创建一个 -test 模块并公开它,而不是使用测试罐。

然而,在我的情况下,这将导致如下循环依赖:

在这种情况下,如何为 maven 保持一个有组织的结构?

Mavens 推荐不使用 test-jar 依赖的原因是

The downside of this solution is that you don't get the transitive test-scoped dependencies automatically. Maven only resolves the compile-time dependencies, so you'll have to add all the other required test-scoped dependencies by hand.

source

因此,如果这不是问题,只需使用 test-jar 依赖项即可。 您也可以只将那些测试 类 和资源打包到您真正想要共享的测试罐中:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                    <configuration>
                        <includes>
                        <!-- include only test resources from that package-->                               <include>**/com/prefabwarek/web/ui/page/include/*</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>