A Maven plugin which fixes Scala dependencies incompatible with Java 9+

Related tags

Build scala-suffix
Overview

scala-suffix Maven Plugin

A Maven plugin which fixes Scala dependencies incompatible with Java 9+.

A bit of context

First of all, you need this plugin only in a corner case situation when:

  1. You have Scala dependencies in your project.
  2. You use Maven.
  3. You use JDK 9 or newer.
  4. At least one of your Scala dependencies lacks the Automatic-Module-Name property in its MANIFEST.MF.

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. 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:

You add a dependency to your pom.xml which looks somehow like this


   your.scala.dependency
   your-scala-dependency_2.13
   1.0.0

You compile the project and you see this warning:

[WARNING] There are 1 pathException(s). The related dependencies will be ignored.
[WARNING] Dependency: /.m2/repository//your-scala-dependency_2.13/1.0.0/your-scala-dependency_2.13-1.0.0.jar
   - exception: Unable to derive module descriptor for /.m2/repository//your-scala-dependency_2.13/1.0.0/your-scala-dependency_2.13-1.0.0.jar
   - cause: your.scala.dependency.2.13: Invalid module name: '2' is not a Java identifier

... and then when you run your program, it crashes when it tries to access the given Scala dependency. Paraphrasing this answer on Stack Overflow, 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.

Usage

Add this to the section of your pom.xml:


  io.github.makingthematrix
  scala-suffix-maven-plugin
  0.2.1
  
    
      your-scala-dependency
    
  
  
    
      
        suffix
      
    
  

where your-scala-dependency is a name of your Scala dependency without the version suffix (if there are more than one, just add them with more tags). This should be the same as artifactId in your section. Or you can use:

groupId:artifactId

if there are more than one dependency with the same artifactId in your project (I noticed that core is a popular name).

The plugin modifies the dependency's JAR file in your local Maven repository. It opens the jar, reads META-INF/MANIFEST.MF and adds to it a line:

Automatic-Module-Name: your-scala-dependency

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.

If you find any problems or if you think some kind of an extended functionality would be valuable, feel free to open a ticket under the Issues tab here on GitHub. I will se what I can do.

Tests

Here's a small Scala+JavaFX project, built with Maven, which you can use to test how the plugin works.

Potential problems

  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.
  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.
  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.

Links to more discussion on this issue

But wait! That's not all!

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:

NAME) ">
Compile / packageBin / packageOptions +=
  Package.ManifestAttributes("Automatic-Module-Name" -> NAME)

(NAME here is the name of the library, without the version suffix).

You might also like...

One file java script for visualizing JDK flight recorder execution logs as flamegraphs without any dependencies except Java and a browser.

Flamegraph from JFR logs Simple one file Java script to generate flamegraphs from Java flight recordings without installing Perl and the Brendan Gregg

Oct 2, 2022

tinylog is a lightweight logging framework for Java, Kotlin, Scala, and Android

tinylog 2 Example import org.tinylog.Logger; public class Application { public static void main(String[] args) { Logger.info("Hello

Dec 30, 2022

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.

A framework for executing native Java code on the GPU. Licensed under the Apache Software License v2 Aparapi allows developers to write native Java co

Dec 29, 2022

Java port of a concurrent trie hash map implementation from the Scala collections library

About This is a Java port of a concurrent trie hash map implementation from the Scala collections library. It is almost a line-by-line conversion from

Oct 31, 2022

Elegant parsing in Java and Scala - lightweight, easy-to-use, powerful.

Please see https://repo1.maven.org/maven2/org/parboiled/ for download access to the artifacts https://github.com/sirthias/parboiled/wiki for all docum

Dec 21, 2022

Elegant parsing in Java and Scala - lightweight, easy-to-use, powerful.

Please see https://repo1.maven.org/maven2/org/parboiled/ for download access to the artifacts https://github.com/sirthias/parboiled/wiki for all docum

Dec 21, 2022

Converting Infix to Postfix and Evaluating Postfix Expression. (Java & Scala).

GUI-Calculator-Infix-to-Postfix Converting Infix to Postfix and Evaluating Postfix Expression. (Java & Scala). Converting Infix to Postfix and Evaluat

Sep 22, 2022

tinylog is a lightweight logging framework for Java, Kotlin, Scala, and Android

tinylog 2 Example import org.tinylog.Logger; public class Application { public static void main(String[] args) { Logger.info("Hello

Jan 4, 2023

ScalaTest is a free, open-source testing toolkit for Scala and Java programmers

ScalaTest is a free, open-source testing toolkit for Scala and Java programmers.

Dec 26, 2022

ASCII renderer in pure java with no external dependencies

Java ASCII Render ASCII renderer in pure java with no external dependencies. Java ASCII Render supports graphical primitives/elements, layers, context

Dec 12, 2022

A lightweight, simple FTP server. Pure Java, no dependencies.

MinimalFTP A lightweight, simple FTP server. Pure Java, no libraries. Features Although it's named "minimal", it supports a bunch of features: 100% Ja

Jan 5, 2023

Transform ML models into a native code (Java, C, Python, Go, JavaScript, Visual Basic, C#, R, PowerShell, PHP, Dart, Haskell, Ruby, F#, Rust) with zero dependencies

m2cgen m2cgen (Model 2 Code Generator) - is a lightweight library which provides an easy way to transpile trained statistical models into a native cod

Jan 4, 2023

A harness to build the source code from openjdk.java.net using Free Software tools and dependencies

A harness to build the source code from openjdk.java.net using Free Software tools and dependencies

Mar 5, 2022

Web-based notebook that enables data-driven, interactive data analytics and collaborative documents with SQL, Scala and more.

Apache Zeppelin Documentation: User Guide Mailing Lists: User and Dev mailing list Continuous Integration: Contributing: Contribution Guide Issue Trac

Jan 8, 2023

A fork of Cliff Click's High Scale Library. Improved with bug fixes and a real build system.

High Scale Lib This is Boundary's fork of Cliff Click's high scale lib. We will be maintaining this fork with bug fixes, improvements and versioned bu

Jan 2, 2023

JMusic bot fork with new features and fixes

JMusic bot fork with new features and fixes

JMusicBot-Fork (by d1m0s23) A cross-platform Discord music bot with a clean interface, and that is easy to set up and run yourself! πŸ“‹ SetupPage Fork

Nov 18, 2022

Carpet Addition for Shadow Item Related Tweaks/Fixes

Carpet Shadow carpet extension to fix various bugs related to shadow item stacks Carpet Settings shadowItemMode what should happen to shadow items whe

Jan 6, 2023

BurritoSpigot is a fork of TacoSpigot 1.8.9 that offers several enhancements to performance as well as bug fixes. while offer extra APIs and support for plugins

🌯 BurritoSpigot 🌯 BurritoSpigot is a fork of TacoSpigot 1.8.8 that offers several enhancements to performance as well as bug fixes. while offer extr

Dec 20, 2022
Releases(0.2.1)
  • 0.2.1(May 14, 2021)

    You can now specify groupId of the artifact you want to fix in the case of having a few dependencies with the same artifactId and wanting to fix only one. You do it with

    <param>groupId:artifactId</param>
    
    Source code(tar.gz)
    Source code(zip)
Owner
Maciej Gorywoda
Scala. Rust. Bicycles. Trying to mix kickboxing with aikido. Trying to be a better person too. Similar results in both cases. πŸ‡ͺπŸ‡ΊπŸ‡΅πŸ‡±
Maciej Gorywoda
A maven archetype for EZCloud scaffolding

ezcloud-archetype English Doc δΈ­ζ–‡ζ–‡ζ‘£ A maven archetype for EZCloud scaffolding. ?? Usage create single project Customize the values of the following par

Project-Hephaestus 2 Feb 8, 2022
Java Ecosystem Capabilities Gradle Plugin

Java Ecosystem Capabilities Gradle Plugin This plugin adds Capabilities to the metadata of well-known components hosted on Maven Central that are used

Jendrik Johannes 17 Dec 6, 2022
A gradle plugin based on ANTLR to generate UML diagrams from kotlin source code.

A gradle plugin based on ANTLR to generate UML diagrams from kotlin source code.

Alex Porter 15 Oct 26, 2022
Jenkins plugin exposes functionalities for the Popcorn by Lectra open-source Jenkins platform on Kubernetes

Popcorn Jenkins Plugin This Jenkins plugin exposes functionalities for the Popcorn by Lectra open-source Jenkins platform on Kubernetes. This plugin i

Lectra 4 Apr 6, 2022
Maven plugin to check if dependencies in CycloneDX BOM files use only allowed licenses.

license-checker-cyclonedx-maven-plugin Maven plugin to check if dependencies in CycloneDX BOM files use only allowed licenses. Quick start guide 1. Ad

null 3 Sep 17, 2022
Paper-nms-maven-plugin - A maven plugin for using NMS on paper with Mojang mappings.

paper-nms-maven-plugin A maven plugin for using NMS on paper with Mojang mappings. This plugin will both create the mapped paper dependency and instal

null 56 Dec 28, 2022
Simple energy convertors for Fabric to stop being bothered by incompatible energy varieties.

EzConvertorz No more pain dealing with EU and E! This mod is open source and under a permissive license. As such, it can be included in any modpack on

Intelligent Creations 3 Jan 9, 2022
fabric-carpet extension mod which attempts to fix as many vanilla bugs as possible. Feel free to add as many fixes as you want!

Carpet-Fixes Fabric Carpet extension mod which attempts to fix as many vanilla bugs as possible! Feel free to contribute by adding as many fixes as yo

Fx Morin 90 Jan 6, 2023
A mod for 1.17 which fixes common bugs in Minecraft

Astatine Astatine is a mod for Minecraft which fixes common bugs in the game Astatine uses the Fabric Mod Loader, Forge will not be supported. About A

Conor Byrne 5 Jul 21, 2022
BungeeCord/Spigot plugin that fixes Multi-world detection by simulating mod presence on the server side

Companion for map mods Unofficial BungeeCord and Spigot (Paper) companion plugin for Xaero's Minimap (and their World Map), JourneyMap and VoxelMap. T

Artur Khusainov 3 Sep 18, 2022