且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Gradle不会复制要构建的测试资源

更新时间:2023-02-17 15:52:46

测试资源的拷贝由Java插件中的processTestResources任务完成。 Java插件还将此指定为测试任务的先决条件,以便在测试运行前发生。

Copying of test resources is done by the processTestResources task from the Java plugin. The Java plugin also specifies this as a prerequisite of the test task, so that it happens before the tests are run.

您已经告诉gradle您的fillDb任务也是一个测试任务的先决条件,但你没有告诉它,processTestResources是你的createDb任务的先决条件。

You have told gradle that your fillDb task is also a prerequisite of the test task BUT you have not told it that processTestResources is a prerequisite of your createDb task.

所以你可以做一些像

task createDb (type:Exec, dependsOn: 'processTestResources') { 
...

BTW测试资源是通过classpath提供给测试的东西。我假设你的测试在运行时不需要实际上你的sql可用,所以他们甚至需要在那里?

BTW test resources are things that are made available to the tests via the classpath. I assume your tests don't need actually your sql available on the classpath at runtime, so do they even need to be there?