redhat-developer / redhat-developer/vscode-java
Depending on a gradle testFixtures module generates java build problems
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 2.3k
- 派生
- 546
- 平均合并
- 20 小时 1 分钟
- 30 天内合并 PR
- 11
描述
Hi, I have a multi-modules gradle/java project in which I'm trying to centralize some test fixtures (aka test helper classes to help build test data etc) in some kind of library module, so that those java test fixtures classes can then be shared in multiple dependant modules (I'm referring precisely to this gradle test fixtures feature).
The problem I'm having in VS Code (with the Java extension) is that once I've defined my test fixtures in the lib module (see steps to reproduce below), as soon as I try to "consume" them by adding the dependency in a gradle dependant module build file (as explained here in gradle doc), something like:
dependencies {
implementation(project(":lib-module"))
testImplementation(testFixtures(project(":lib-module")))
}
it will create compile errors under the vs code Problems tab that the dependant module can no longer see any dependency imports made by the basic implementation(project(":lib-module")).
However, if I build everything with gradle, it will work just fine. The reported compile errors are only visual, within the Problems tab of the vscode editor.
Then, if I comment out the gradle testFixtures dependency import as follow:
dependencies {
implementation(project(":lib-module"))
//testImplementation(testFixtures(project(":lib-module")))
}
all compile errors will be gone from the vs code Problems tab, BUT, then if I try to run a gradle build task, it will fail saying that my tests no longer have access to the test fixtures imports from the lib module.
This seems to me like an issue with the vscode-java extension (or upstream?) not supporting properly the gradle testFixtures feature, preventing us from sharing in a very simple way test fixtures among multiple modules.
Environment
Operating System: macOS big sur (11.6.5)
JDK version: openjdk version "17.0.4.1" 2022-08-12
Visual Studio Code version: 1.71.0
Java extension version: 1.12.0
Steps To Reproduce
- Create a multi-modules gradle java project (2 modules should be enough, the lib exposing both normal lib utility/service classes and also test fixtures)
- Create one normal utility class in the lib module, can be just a simple pojo... (
<lib-module>/src/main/java/com/...) - Create one test fixture class also under the lib module, can be just a simple pojo... (
<lib-module>/src/testFixture/java/com/...) - Add the gradle test Fixtures plugin under your lib gradle build file (
<lib-module>/build.gradle)
plugins {
// A Java Library
id 'java-library'
// which produces test fixtures
id 'java-test-fixtures'
}
- In the second dependant module, create one normal class that will consume/import the utility class from the lib module created in step 2 (
<dependant-module>/src/main/java/com/...) - In the second dependant module, create a test class that will consume/import the test fixture class from the lib module created in step 3 (
<dependant-module>/src/test/java/com/...), the test class can just be a simple pojo, no need to import any test framework for this, we're just testing dependencies between gradle modules... - Add the dependencies under the dependant module's gradle build file, so that it sees both the utility class AND the test fixture class from the lib module (
<dependant-module>/build.gradle):
dependencies {
implementation(project(":lib-module"))
testImplementation(testFixtures(project(":lib-module")))
}
- Save everything, and you should expect to see compile errors in the vs code Problems tab, complaining about the fact that your dependant module's normal pojo class created in step 5 is unable to import the utility class from the lib module (that's right, the error might not even be inside your test class, but it could, it all depends where you've imported the lib utility class in this example, whether it's within the normal class in step 5, but it could have been under your test class of step 6 too; bottom line is, the compile error will be related to the normal lib classes that can no longer be imported in the dependant module(s); the test fixtures classes 'are' being imported properly.. So it really seems like if importing the 'test fixtures' will PREVENT the normal lib classes from being imported).
Sample project
I've created this basic sample project which reproduces the error:
https://github.com/Frank-D/multi-modules-root
Current Result
Compile errors showing under vs code Problems tab (e.g., using gradle test fixtures lib dependency hides the basic lib module dependency).
Expected Result
No compile errors showing under vs code Problems tab (e.g. using gradle test fixtures works without any issue within vs code using the vscode-java extension).
Additional Informations
Here's a screenshot of the vs code Problems, when reproducing the described error with the previous 'Sample project':

贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的示例项目开始,使用 lib-module/build.gradle 和依赖模块的 build.gradle 复现该问题,并包含两个项目依赖项。将 VS Code 的 Problems 选项卡与成功的 Gradle 构建进行比较,重点关注 java-test-fixtures 依赖项如何影响普通库导入的可见性。当 fixture 导入和普通库导入都能正常工作且没有可见的编译错误时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, vscode
- 领域
- build-system, developer-experience, tooling
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100