Maven 类路径中的Jigsaw测试依赖关系:为什么另一个JAR中的超类不可访问?
我目前正在测试使用JDK9EA+147和Maven编译器插件3.6.0将现有的Java8(Maven)项目迁移到Java9/Jigsaw 我已将Maven 类路径中的Jigsaw测试依赖关系:为什么另一个JAR中的超类不可访问?,maven,classpath,java-9,java-platform-module-system,Maven,Classpath,Java 9,Java Platform Module System,我目前正在测试使用JDK9EA+147和Maven编译器插件3.6.0将现有的Java8(Maven)项目迁移到Java9/Jigsaw 我已将src目录转换为模块,并将test目录保留为非模块化目录 在testCompile期间,我收到一个意外错误: 错误:ExtractedArtifactStoreBuilder中的build()是在不可访问的类或接口中定义的 当然,我已经检查了ExtractedArtifactStoreBuilder是否是公共的build()继承自其(public)超类和
src
目录转换为模块,并将test
目录保留为非模块化目录
在testCompile
期间,我收到一个意外错误:
错误:ExtractedArtifactStoreBuilder中的build()是在不可访问的类或接口中定义的
当然,我已经检查了ExtractedArtifactStoreBuilder
是否是公共的build()
继承自其(public)超类和public。代码在JDK 8中编译并运行良好
ExtractArtifactStoreBuilder
是在与其超类不同的第三方JAR中定义的,但是Maven正确地将两者都放在类路径中。令人困惑的是,超类具有相同的类名(但驻留在不同的包中)
就我所见,我应该能够访问测试代码中的公共继承方法。那么这是jdk9早期访问版本中的一个bug吗
编辑:为了更好地理解,这里对所涉及的JAR和类进行了一些抽象,减少了混乱的命名和不重要的内容(有关实际的依赖项,请参见下文): process.jar
public ProcessStoreBuilder
public ProcessStoreBuilder download(...) // returns "this"
public ... build()
public MongoStoreBuilder extends ProcessStoreBuilder
mongo.jar
public ProcessStoreBuilder
public ProcessStoreBuilder download(...) // returns "this"
public ... build()
public MongoStoreBuilder extends ProcessStoreBuilder
src/test/java/ExampleTest
mongoStoreBuilder.download(...).build()
// ^ breaks at compile time, saying that
// ProcessStoreBuilder#build() is not accessible
我已经能够在最小的设置中重现该行为: pom.xml(节选) src/test/java/ExampleTest.java(节选)
涉及的类和jar有点混乱。如果您总结了哪个类在哪个JAR/模块中(包括测试类)以及它们有哪些作用域,这会有所帮助。奇怪的是,您的模块描述符是空的。你的模块不依赖于任何东西吗?我非常同意,我花了一些时间来理解和总结这个模块。我会再试一次,希望把事情弄清楚。模块描述符为空,因为代码来自我创建的用于隔离行为的最小设置。当然,原来的应用程序有更多的依赖关系。@Nicolai我在上面添加了一点抽象,我希望这能澄清问题。谢谢你的提示:)
@Before
public void setUp() throws Exception {
// both `download` and `build` are inherited from the superclass
// the following does work
// de.flapdoodle.embed.mongo.config.ExtractedArtifactStoreBuilder
ExtractedArtifactStoreBuilder easb = new ExtractedArtifactStoreBuilder();
easb.download(new DownloadConfigBuilder().build());
easb.build();
// but this does not
// download returns the same instance but has the superclass as return type
// de.flapdoodle.embed.process.store.ExtractedArtifactStoreBuilder
// the compiler can't see the `build` method of the superclass
new ExtractedArtifactStoreBuilder()
.download(new DownloadConfigBuilder().build())
.build();
}