我预计可以在myModuleA中使用ie Guava-19,在myModuleB中使用guava-20,因为jigsaw模块有自己的类路径.
假设myModuleA使用Iterators.emptyIterator(); - 在guava-20中删除,myModuleB使用新的静态方法FluentIterable.of(); - 番石榴-19没有.不幸的是,我的测试是否定的.在编译时,它看起来很好.与运行时相反,结果是NoSuchMethodError.意味着,类加载器中的第一个类决定哪个失败.
与底层耦合的封装?我找到了自己的理由.由于传递依赖性会产生与以前相同的问题,因此无法支持它.如果在ModuleA和ModuleB中的签名中发生版本冲突的guava类依赖于它.应该使用哪个班级?
但为什么我们可以通过互联网阅读"拼图 - 模块系统停止类路径地狱"?我们现在有多个较小的"类似路径",但问题相同.这不仅仅是一个问题,而是一个不确定性.
为了理解我们的类别:
类路径中的所有类和jar都将是未命名模块的一部分.但为什么我们需要什么呢?自动模块的优势在哪里?我可以"要求"那些该死的传统罐子,使它们成为一个自动模块.我没有把它包括在内吗?
这个应用程序出了什么问题.我认为classpath jar和模块jar的混合是有效的.对于没有明确模块信息的所有罐子成为自动模块?当我删除我的module-info.java时,它可以工作.因为IDEA在这种情况下使用了类路径.
Java(TM)SE运行时环境(版本9 + 176)
IntelliJ IDEA 2017.1.4
module-info.java
module test {
requires spring.boot.autoconfigure;
requires spring.boot;
}
Run Code Online (Sandbox Code Playgroud)
App.java
package com.foo.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M2</version>
</parent>
<name>test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url> …Run Code Online (Sandbox Code Playgroud)