Skip to content

Commit f8d5e31

Browse files
Update README.md
1 parent 4611302 commit f8d5e31

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ A Maven plugin which fixes Scala jars incompatibility with Java 9+.
55
### A bit of context
66

77
First of all, you need this plugin only in a corner case situation when:
8+
89
1. You have Scala dependencies in your project.
910
2. You use Maven.
1011
3. You use JDK 9 or newer.
1112
4. At least one of your Scala dependencies lacks the `Automatic-Module-Name` property in its `MANIFEST.MF`.
12-
13-
If any of those points is not true, `scala-suffix-maven-plugin` will not help you. But if they are, and you're here, it's possible that it's because you have already been bitten by a problem similar to the following:
13+
14+
Using Maven with Scala libraries is rare, so there's not much demand to solve this issue. But if a project makes extensive use of Java libraries, it might make sense to build it with Maven instead - or if it uses a Maven plugin which has to sbt alternative, [as in my case](https://github.com/makingthematrix/scalaonandroid). So, if any of those points is not true, you will either not need `scala-suffix-maven-plugin` or it will not help you. But if they are, and you're here, it's possible that it's because you have already been bitten by a problem similar to the following:
1415

1516
You add a dependency to your `pom.xml` which looks somehow like this
1617
```
@@ -31,6 +32,10 @@ You compile the project and you see this warning:
3132
... and then when you run your program, it crashes when it tries to access the given Scala dependency.
3233
Paraphrasing [this answer on Stack Overflow](https://stackoverflow.com/questions/48714633/automatic-module-name-containing-number/48714979#48714979), since Java 9, Java does not recognize suffixes in modules names like `_2.13` as version numbers and treat them as integral parts of modules names. So, when your project tries to use a class from the Scala dependency, it will look for `your.scala.dependency.2.13` instead of just `your.scala.dependency`, it will fail to do it, and it will crash.
3334

35+
### Installation
36+
37+
TBD. (I need some time to upload the plugin to Maven Central. Until then you would have to download the source code and compile the plugin manually, and I would prefer to spare you this).
38+
3439
### Usage
3540

3641
Add this to the `<plugins>` section of your `pom.xml`:
@@ -59,10 +64,31 @@ The plugin modifies the dependency's JAR file in your local Maven repository. It
5964
```
6065
Automatic-Module-Name: your-scala-dependency
6166
```
62-
if it is missing. If the property `Automatic-Module-Name` already exists, the plugin does nothing - we assume that in that case the dependency should already work. This prevents the plugin from modifying the same JAR file more than once.
67+
If the property `Automatic-Module-Name` already exists, the plugin does nothing - we assume that in that case the dependency should already work. This prevents the plugin from modifying the same JAR file more than once.
6368

64-
#### Potential problems
69+
### Potential problems
6570

6671
1. If `Automatic-Module-Name` already exists but is set to a value that is still invalid for Java 9+, the plugin won't fix this.
6772
2. The plugin changes the contents of the JAR file, but it does not update the checksum. If you check it later on, it won't match.
6873
3. The plugin relies on that you don't need two versions of the same Scala library for different Scala versions. If you do (but... why?) it will modify only one of them and ignore the other.
74+
75+
### Links to more discussion on this issue
76+
77+
* https://dzone.com/articles/automatic-module-name-calling-all-java-library-maintainers
78+
* https://users.scala-lang.org/t/scala-jdk-11-and-jpms/6102
79+
* https://stackoverflow.com/questions/48714633/automatic-module-name-containing-number/48714979#48714979
80+
* https://stackoverflow.com/questions/46683561/how-to-resolve-a-maven-dependency-with-a-name-that-is-not-compliant-with-the-jav/46685325#46685325
81+
* https://stackoverflow.com/questions/59844195/how-to-add-spark-dependencies-in-spring-boot-multi-module-java-11-project/59844858#59844858
82+
* https://stackoverflow.com/questions/46501388/unable-to-derive-module-descriptor-for-auto-generated-module-names-in-java-9
83+
84+
### But wait! That's not all!
85+
86+
If you are a creator of a Scala library, you can simply add the `Automatic-Module-Name` property to `META-INF/MANIFEST.MF` by yourself. In most cases, people will use your library with sbt and then this won't be necessary, but it won't hurt them either, and while doing this you will help people who use Maven. In case you use sbt for building your library, all you need to do is at these two lines somewhere in your `build.sbt`:
87+
```
88+
Compile / packageBin / packageOptions +=
89+
Package.ManifestAttributes("Automatic-Module-Name" -> name.value)
90+
```
91+
(`name` here is the name of the library, without the version suffix).
92+
93+
94+
I hope you will find this plugin useful.

0 commit comments

Comments
 (0)