gradlex-org / extra-java-module-info

A Gradle 6.8+ plugin to use legacy Java libraries as Java Modules in a modular Java project
Apache License 2.0
104 stars 6 forks source link

[Maybe] Make name derivation for Automatic Modules configurable #149

Open jjohannes opened 1 month ago

jjohannes commented 1 month ago

Following up on this request.

As Java itself, this plugin produces invalid names for certain Jars if deriveAutomaticModuleNamesFromFileNames = true is used.

As @satsen pointed out, sometimes there are patterns in Jar names, which could be translated differently to get a valid result. Then not each of the invalid names need to be configured. A good example are Scala libraries, which always have the Scala vesion inside a Jar name. For example: circe-core_2.12-0.13.0.jar --> circe.core.2.12.

As a feature for this, I could imagine a configuration option that takes the same arguments as Java's String.replaceAll() and then applies that on the derived name.

deriveAutomaticModuleNamesFromFileNames = true
deriveAutomaticModuleNamesReplaceAll("\\.[0-9]+", "") // same semantics as String.replaceAll("\\.[0-9]+", "")
deriveAutomaticModuleNamesReplaceAll("circe\\.", "io.circe.")
// possibly more "deriveAutomaticModuleNamesReplaceAll()", will be applied in definition order

The above example would do: circe-core_2.12-0.13.0.jar --name derivation-> circe.core.2.12 --replaceAll--> circe.core --replaceAll--> io.circe.core