When we use opaque types to glue osgi modules we will recive unnecessary binary dependencies.
So we need providing and loading absolutely useless jars.
Example
TestContract.scala
:
//It can be automaticly generated
object TestContract:
opaque type TestContract = AnyRef
inline def apply(underlying: AnyRef): TestContract = underlying
extension (testContract: TestContract)
//it can be dynamic invocation or something else
inline def helloWorld():Unit = println(testContract.toString())
Main.scala
:
@main def hello(): Unit =
//The object from other classloader
val testObject= "Hello world"
TestContract(testObject).helloWorld()
Decompilatin of hello
method:
public void hello() {
//Useless binary dependencies which actualy is not used
TestContract$ testContract$1 = TestContract$.MODULE$, testContract$2 = TestContract$.MODULE$, TestContract$_this = testContract$2;
//TestContract(testObject).helloWorld()
String testContract$proxy1 = "Hello world";
Predef$.MODULE$.println(testContract$proxy1.toString());
}
Questions
Is there any way to garantee that there will not be unnecessary binary dependencies(TestContract$.MODULE$
)?
Or would it be posible to annotate such objects(TestContract
) to prevent useless binary dependencies?