Libgdx 未找到来自 gradle 命令行资产的测试
Libgdx test from gradle command line assets not found
我有一个带有一些测试的 LibGDX 项目。结构如下:
- core/src -> 对于我的 java 源代码
- core/test -> 我的测试源代码
- core/assets -> 我所有的资产
当我 运行 来自 eclipse 的测试时,它们都变绿了,但是每当我尝试从 gradle 命令行 运行 它们时(./gradlew测试)资产文件夹出错。我相信这是因为测试不是从 assets 文件夹启动的,因为它是从 eclipse 启动的。
我怎么解决这个问题 ?有没有办法告诉 gradle 在 运行 测试时使用 core/assets 作为工作区目录?
这是我得到的错误:
com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: myasset.png
我找到了实现我想要的方法。我 post 在这里为可能需要它的任何人提供我的解决方案。 gradle中的测试任务有一个名为workingDir
的属性。所以我只需要将它设置到正确的文件夹。在项目的 build.gradle
文件(根文件夹)中,只需添加以下部分:
project(":core") {
apply plugin: "java"
// Add the following test section
test{
workingDir= new File("/assets")
}
// Rest of the file
}
就是这样!我的测试现在在命令行中 运行 绿色。
我有一个带有一些测试的 LibGDX 项目。结构如下:
- core/src -> 对于我的 java 源代码
- core/test -> 我的测试源代码
- core/assets -> 我所有的资产
当我 运行 来自 eclipse 的测试时,它们都变绿了,但是每当我尝试从 gradle 命令行 运行 它们时(./gradlew测试)资产文件夹出错。我相信这是因为测试不是从 assets 文件夹启动的,因为它是从 eclipse 启动的。
我怎么解决这个问题 ?有没有办法告诉 gradle 在 运行 测试时使用 core/assets 作为工作区目录?
这是我得到的错误:
com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: myasset.png
我找到了实现我想要的方法。我 post 在这里为可能需要它的任何人提供我的解决方案。 gradle中的测试任务有一个名为workingDir
的属性。所以我只需要将它设置到正确的文件夹。在项目的 build.gradle
文件(根文件夹)中,只需添加以下部分:
project(":core") {
apply plugin: "java"
// Add the following test section
test{
workingDir= new File("/assets")
}
// Rest of the file
}
就是这样!我的测试现在在命令行中 运行 绿色。