davidB / scala-maven-plugin

The scala-maven-plugin (previously maven-scala-plugin) is used for compiling/testing/running/documenting scala code in maven.
https://davidb.github.io/scala-maven-plugin/
The Unlicense
554 stars 150 forks source link

Getting object scala in compiler mirror not found issue while running the application using jar #749

Closed AlokhPD11 closed 4 months ago

AlokhPD11 commented 4 months ago

I have a multi-module application which has a java HTTP application (springboot, java 11) in one module and scala code in the second module.

The second module is included as a dependency in the first module as code in the second module needs to get invoked on REST invocations.

Here is a minimal project to reproduce the issue.

Steps to reproduce the issue

mvn clean compile
java -jar scala-compiler-issue-service/target/scala-compiler-issue-service-1.0-SNAPSHOT.jar

The above command to run the application fails on initialisation of the scala compiler.

Caused by: scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
        at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:24) ~[scala-reflect-2.12.16.jar!/:na]
        at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:25) ~[scala-reflect-2.12.16.jar!/:na]
        at scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$5(Mirrors.scala:61) ~[scala-reflect-2.12.16.jar!/:na]
        at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:61) ~[scala-reflect-2.12.16.jar!/:na]

Interesting thing here is once we run the application using -cp command and pass the scala jars in classpath then the initialisation does not fail

java -cp scala-compiler-issue-service/target/scala-compiler-issue-service-1.0-SNAPSHOT.jar:scala-reflect-2.12.16.jar:scala-compiler-2.12.16.jar:scala-library-2.12.16.jar -Dloader.main=org.example.ServiceAPIApplication org.springframework.boot.loader.PropertiesLauncher

The 3 scala jars used are included in the project. They are fetched from maven repository using

wget https://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.16/scala-reflect-2.12.16.jar
wget https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.16/scala-library-2.12.16.jar
wget https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.12.16/scala-compiler-2.12.16.jar
AlokhPD11 commented 4 months ago

Hi @davidB can you please take a look at this issue and help us with what further steps I could take to resolve this ?

slandelle commented 4 months ago

I don't think your issue has anything to do with this plugin.

This plugin only takes care of compiling the Scala code. Your issue happens at runtime, because some classes are missing from the classpath. Are you're expecting your jar to be a fatjar containing all the transitive dependencies of your module? If so, your issue is with this repackager (spring-boot?).

AlokhPD11 commented 4 months ago

Thanks you for the response @slandelle, will check with the spring-boot community regarding this.