Package conflicts with automatic modules in Java 9
Am I using the new module system correctly?
Yes. What you are seeing is intended behavior, and this is because JPMS modules do not allow split packages.
In case you are not familiar with the term "split packages" it essentially means two members of the same package coming from two different modules.
For example:
com.foo.A (from moduleA.jar)
com.foo.B (from moduleB.jar)
What can I do about this error?
You have two options:
- (harder) "unsplit" the package dependencies. However this could be difficult or impossible if you are not familiar with the inner workings of the library
- (easier) combine the two jars into a single jar (and therefore a single automatic module) as you mentioned above. I agree that it is not a "good" solution, but having split packages in the first place is generally not a good idea either.
Do these dependencies prevent me from updating, or should I just wait for rx to update their libs?
Hopefully rx will eventually update their libs to not have split packages at some point in the future. Until then, my recommendation would be to just smash the two jars together into a single jar (option #2).
I had simmiliar problem:
error: module flyway.core reads package javax.transaction.xa from both jboss.transaction.api.1.2.spec and java.sql
error: module slf4j.api reads package javax.transaction.xa from both jboss.transaction.api.1.2.spec and java.sql
error: module hibernate.core reads package javax.transaction.xa from both jboss.transaction.api.1.2.spec and java.sql
.../src/main/java/module-info.java:1: error: module eu.com.x reads package javax.transaction.xa from both java.sql and jboss.transaction.api.1.2.spec
I could get rid of split packages compilation problem by checking my project transitive dependencies ("gradle dependencies" or "mvn dependency:tree" could be helpful) and excluding by code simmiliar to:
configurations.all {
exclude group: 'org.jboss.spec.javax.transaction', module: 'jboss-transaction-api_1.2_spec'
}
or
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
No jar repackaging was needed im my problem. This problem have not occured on #JDK8. Probably excluding dependencies does not help in every project.