Description
We noticed a "regression" in 1.2.x
and 1.3.x
when patching several besu-native Jars to add a module-info.class
file to use them on the --module-path
. It was introduced with #245. We get the following error:
Error occurred during initialization of boot layer
java.lang.LayerInstantiationException: Package lib.aarch64 in both module org.hyperledger.besu.nativelib.secp256k1 and module org.hyperledger.besu.nativelib.arithmetic
Gradle build scan with failing test runs
The reason is that, in the Module System (--module-path), folders in Jar files are interpreted as Java packages even if they do not contain class
files. Then, the strict package visibility rules of the Module System apply which do not allow the same package in multiple Jars (modules).
In #245, a folder structure was introduced, where the folder no longer contain a -
(which is forbidden in package names). Now, the folders with the native binaries are interpreted as package by Java several jars share the same packages such as lib/aarch64
.
A good solution would be to have the native Jars in a dedicated package in each library. like lib/secp256k1/...
. If that is too complicated to do with the implementation, reintroducing -
symbols in the parent folder – e.g. native-libs
should also fix the issue I believe.
Reproducer as Gradle build. In an empty folder, add:
src/main/java/module-info.java
(example code)
module org.example {
requires org.hyperledger.besu.nativelib.arithmetic;
requires org.hyperledger.besu.nativelib.secp256k1;
}
src/main/java/org/example/App.java
(example code)
package org.example;
public class App {
public static void main(String[] args) { }
}
settings.gradle.kts
(empty)build.gradle.kts
plugins {
id("application")
id("org.gradlex.extra-java-module-info") version "1.12" // for Jar patching
}
repositories {
maven("https://hyperledger.jfrog.io/artifactory/besu-maven")
mavenCentral()
}
extraJavaModuleInfo {
// Add empty module-info.class to Jars
module("org.hyperledger.besu:arithmetic", "org.hyperledger.besu.nativelib.arithmetic") {}
module("org.hyperledger.besu:secp256k1", "org.hyperledger.besu.nativelib.secp256k1") {}
}
application {
mainModule = "org.example"
mainClass = "org.example.App"
}
dependencies {
implementation("org.hyperledger.besu:secp256k1:1.3.1")
implementation("org.hyperledger.besu:arithmetic:1.3.1")
}
Then execute gradle run
to get the package in both modules error.