9

I get tons of "split package" errors, when I introduce java 9 modules in my SpringBoot code. They are everywhere, eg.:

Error:java: the unnamed module reads package org.bson.types from both bson and mongodb.driver
Error:java: the unnamed module reads package org.bson.io from both bson and mongodb.driver
Error:java: the unnamed module reads package org.bson from both bson and mongodb.driver
Error:java: the unnamed module reads package com.mongodb.client.model from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package com.mongodb.client from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package com.mongodb from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package org.aopalliance.aop from both aopalliance.repackaged and spring.aop
...

I have tried with lots of different releases, including 1.5.3.RELEASE, 2.0.0.M5 and 2.0.0.BUILD-SNAPSHOT.

The problems seem to come when maven takes all dependencies and add them as "Automatic Modules" on the module-path. Many of the dependencies have duplicated packages, which is not allowed in java 9. An examples of a bad dependency is spring.aop:5.0.1.BUILD-SNAPSHOT that obviously packages org.aopalliance.aop.

It is SpringBoot that defines all the dependencies. I even tried to use a vanilla project from spring initializr, adding only:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

Furthermore, I added a module-info.java to make the demo code java 9 compliant:

├── src
│   ├── main
│   │   ├── java
│   │   │   ├── com
│   │   │   │   └── example
│   │   │   │       └── demo
│   │   │   │           └── DemoApplication.java
│   │   │   └── module-info.java
│

This doesn't compile.

Question: Does anyone have a working example of a SpringBoot project, where the code is organised in java 9 modules?

Naman
  • 27,789
  • 26
  • 218
  • 353
  • 5
    Possible duplicate of [java 9 module reads package X from A and B](https://stackoverflow.com/questions/44463552/java-9-module-reads-package-x-from-a-and-b)... and to answer an interesting question there - **No**, its not just you :) ++ Avoid asking too many unrelated questions in one. Do take a look at this as well https://stackoverflow.com/questions/42358084/package-conflicts-with-automatic-modules-in-java-9/42358212#42358212, based on gradle but general answer. – Naman Oct 16 '17 at 14:31
  • 1
    Thanks for your advice about multiple questions, and the reference to the other post. Unfortunately I cannot use that solution because the split packages problem is in many places including SpringBoots own artifacts. I think that the SpringBoot team must address this problem, and come up with a guide for how to solve this issue. But I would love to see a working example. – Christian von Wendt-Jensen Oct 17 '17 at 05:30
  • In which case, you shall await for the bottom-up approach and let `spring-boot` release artifact with a modularized code.... *would love to see a working example* , seems more of a sneak peek for which I believe SO is not an appropriate place. – Naman Oct 17 '17 at 05:33
  • 2
    If that is the case, that SpringBoot isn't ready, then so be it. But I was confused about the state of SpringBoot, and therefore I reach out to the community of SO. Nothing to do with sneak peek :-) – Christian von Wendt-Jensen Oct 17 '17 at 05:45

0 Answers0