Differences and connections between SBT, MAVEN, and IVY

Table of contents

java.lang.NoClassDefFoundError: scala/reflect/internal/Trees

Differences and connections between SBT, MAVEN, and IVY

references

 

java.lang.NoClassDefFoundError: scala/reflect/internal/Trees

When writing a Scala program with maven, the following error is reported.

Error:scalac: Error: scala/reflect/internal/Reporter
java.lang.NoClassDefFoundError: scala/reflect/internal/Reporter
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sbt.compiler.RawCompiler.apply(RawCompiler.scala:25)
	at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:146)
	at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:142)
	at sbt.IO$.withTemporaryDirectory(IO.scala:291)
	at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:142)
	at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:139)
	at sbt.IO$.withTemporaryDirectory(IO.scala:291)
	at sbt.compiler.AnalyzingCompiler$.compileSources(AnalyzingCompiler.scala:139)
	at sbt.compiler.IC$.compileInterfaceJar(IncrementalCompiler.scala:52)
	at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$.getOrCompileInterfaceJar(CompilerFactoryImpl.scala:96)
	at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:50)
	at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:49)
	at scala.Option.map(Option.scala:146)
	at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.getScalac(CompilerFactoryImpl.scala:49)
	at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.createCompiler(CompilerFactoryImpl.scala:22)
	at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:24)
	at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:24)
	at org.jetbrains.jps.incremental.scala.local.Cache$$anonfun$getOrUpdate$2.apply(Cache.scala:20)
	at scala.Option.getOrElse(Option.scala:121)
	at org.jetbrains.jps.incremental.scala.local.Cache.getOrUpdate(Cache.scala:19)
	at org.jetbrains.jps.incremental.scala.local.CachingFactory.createCompiler(CachingFactory.scala:23)
	at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:22)
	at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:68)
	at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:25)
	at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)
Caused by: java.lang.ClassNotFoundException: scala.reflect.internal.Reporter
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 46 more

For this question, after searching for answers, I tried to delete the files under the ~/.ivy2 path. It seems that idea uses the dependencies under this path by default? But another new error will be reported:

Error:scalac: error while loading package, class file '/usr/local/Cellar/maven/3.6.0/libexec/conf/repository/org/scala-lang/scala-library/2.13.1/scala-library-2.13.1.jar(scala/collection/immutable/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)

 Looking at the error message, it is because the version is wrong. This is because there is a version correspondence between Spark and scala:

 You can see that the spark version corresponding to Scala-2.12 is 2.4.5, but I am using version 2.1.1, so I need to change the scala version back to 2.11. But then this error is reported again:

java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;

This is again because the Scala-sdk version is inconsistent, and the scala-sdk is also replaced with version 2.11.

 In addition, it should be noted that the 2.11.8 version should be moved up in Modules, otherwise the previous version will still be used.

 

Differences and connections between SBT, MAVEN, and IVY

SBT, MAVEN, and IVY often appear together, but I haven't specifically understood what they are before.

SBT  is a Scala build tool, the full name is Simple Build Tool, similar to Maven or Gradle.

Maven2, it is a modular project construction tool (Building a Project). It manages dependencies, build cycles, tests, packages and publishes your artifacts in repositories. It's a project build tool that's ahead of the usual build tools (in fact its first version was a layer on top of Ant).
Apache ivy2 can manage the files that the project depends on in a unified way, relying on ant, which is a tool for managing (recording, tracking, parsing and reporting) project dependencies (dependency tool).

Maven 2 and Ivy are often compared together, but they are actually different types of tools. Ivy only provides dependency management functionality, but Maven 2 is a comprehensive tool for software project management that can manage builds, reports, documentation, and dependencies from a centralized source. Ant and Ivy 2.0 are integrated together, and the comparison with Maven 2 is more appropriate.

The two tools differ in the way they handle conflict management, which refers to the ability to resolve conflicts when dealing with transitive dependencies. Ivy allows customization of conflict managers and rules by module, while Maven 2's conflict management is based on the most recent definition (that is, a module depends on foo 1.0, which causes all dependencies of the module to not use foo 1.1).

Maven 2 handles the dependency configuration through a concept called scope. In Maven 2, a dependency is only valid for the test or build phase in which it was defined. Ivy has the ability to create multi-configuration maps that bind each configuration (declarations for build artifacts) with dependencies of other modules, providing even more customization options.

Compared with Maven 2's limited documentation on dependency management, Ivy's documentation is more extensive, including a large number of examples and guidelines, as well as FAQs. For enterprises that cannot use public repositories and have invested heavily in Ant-based build systems, Ivy supports the creation of enterprise repositories and is tightly integrated with Ant. These additional features make Ivy a viable alternative to Maven 2 Dependency management tool.

references

[1]https://stackoverflow.com/questions/25126238/java-lang-noclassdeffounderror-scala-reflect-internal-trees

[2]https://issues.sonatype.org/browse/MVNCENTRAL-485

[3]http://ant.apache.org/ivy/history/2.0.0/settings/caches.html

[4] https://zhuanlan.zhihu.com/p/85849204

 

Guess you like

Origin blog.csdn.net/qq_35590459/article/details/105480262