現在、jdk9-ea+147 と maven-compiler-plugin 3.6.0 を使用して、既存の Java 8 (Maven) プロジェクトを Java 9 / Jigsaw に移行するテストを行っています。
src
ディレクトリをモジュールに変換し、ディレクトリをtest
非モジュールのままにしました。
予期testCompile
しないエラーが発生しました:
エラー: ExtractedArtifactStoreBuilder の build() が、アクセスできないクラスまたはインターフェイスで定義されています
もちろん、両方ExtractedArtifactStoreBuilder
が公開されていることを確認しました。build()
(パブリック) スーパークラスおよびパブリックからも継承されます。このコードは、JDK 8 で正常にコンパイルおよび実行されます。
ExtractArtifactStoreBuilder
スーパークラスとは異なるサードパーティ JAR で定義されていますが、Maven は両方をクラスパスに正しく配置します。紛らわしいことに、スーパークラスのクラス名は同じです (ただし、別のパッケージに存在します)。
私が見る限り、テスト コードでパブリックに継承されたメソッドにアクセスできるはずです。これは jdk9 アーリー アクセス バージョンのバグですか?
編集:より理解しやすいように、関連する JAR とクラスを少し抽象化したものを次に示します。名前の混乱が少なく、重要でないものは省略されています (実際の依存関係については、以下を参照してください)。
プロセス.jar
public ProcessStoreBuilder
public ProcessStoreBuilder download(...) // returns "this"
public ... build()
mongo.jar
public MongoStoreBuilder extends ProcessStoreBuilder
ソース/テスト/Java/ExampleTest
mongoStoreBuilder.download(...).build()
// ^ breaks at compile time, saying that
// ProcessStoreBuilder#build() is not accessible
最小限のセットアップで動作を再現できました。
pom.xml(抜粋)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>9</source>
<target>9</target>
<debug>true</debug>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>1.50.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.process</artifactId>
<version>1.50.0</version>
<scope>test</scope>
</dependency>
</dependencies>
src/main/java/module-info.java
module com.mycompany.example.testdependencyexample {}
src/test/java/ExampleTest.java (抜粋)
@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();
}