Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Error: java.lang.ClassNotFoundException: mdoc.Main #4

Open
hmf opened this issue Sep 23, 2022 · 1 comment
Open

Error: java.lang.ClassNotFoundException: mdoc.Main #4

hmf opened this issue Sep 23, 2022 · 1 comment

Comments

@hmf
Copy link

hmf commented Sep 23, 2022

I have set-up a simple build.sc to use mdoc but am getting the error.

Compiling /home/hmf/VSCodeProjects/stensorflow/build.sc
[40/40] tutorial.mdoc 
1 targets failed
tutorial.mdoc java.lang.ClassNotFoundException: mdoc.Main
    java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
    mill.api.ClassLoader$$anon$1.findClass(ClassLoader.scala:47)
    java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
    java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    mill.modules.Jvm$.getMainMethod(Jvm.scala:268)
    mill.modules.Jvm$.$anonfun$runLocal$1(Jvm.scala:262)
    mill.util.Jvm$.inprocess(Jvm.scala:30)
    mill.modules.Jvm$.inprocess(Jvm.scala:288)
    mill.modules.Jvm$.runLocal(Jvm.scala:256)
    de.wayofquality.mill.mdoc.MDocModule.$anonfun$mdoc$2(MDocModule.scala:23)
    mill.define.Task$TraverseCtx.evaluate(Task.scala:380)

I am using:

import mill._
import mill.api.Loose
import mill.define.{Target, Task}
import scalalib._
import coursier.core.Resolution
import java.io.File

// Import JavaCPP to get host OS name
import $ivy.`org.bytedeco:javacpp:1.5.7`

// Add simple mdoc support for mill
// https://mvnrepository.com/artifact/org.scalameta/mdoc
import $ivy.`org.scalameta::mdoc:2.3.3`
//import $ivy.`org.scalameta::mdoc:2.2.4`
import $ivy.`de.wayofquality.blended::de.wayofquality.blended.mill.mdoc::0.0.4-2-2f8b5e`
import de.wayofquality.mill.mdoc.MDocModule

val ScalaVersion         = "3.2.1-RC2" // "3.1.3"
val mUnitVersion         = "1.0.0-M6" 
val javaCPPVersion       = "1.5.7"
val tensorflowVersion    = "0.4.1" // TF:2.7.1

object tutorial extends ScalaModule with MDocModule {
  // Also used by mill-mdoc
  override def scalaVersion = T{ ScalaVersion }

  override def javacOptions = T{ Seq("-source", "17", "-target", "17", "-Xlint") }
  override def scalacOptions = T{ Seq("-deprecation", "-feature") }

  // mdoc
  override def scalaMdocVersion = "2.3.3" // "2.2.4"
  override def mdocSources = T.sources{ T.workspace / "docs" }  

  def javaCPPPlatform = T{ org.bytedeco.javacpp.Loader.Detector.getPlatform }

  override def ivyDeps = Agg(
      ivy"org.tensorflow:tensorflow-core-api:${tensorflowVersion}",
      ivy"org.tensorflow:tensorflow-core-api:${tensorflowVersion};classifier=${javaCPPPlatform()}"
  )

  object test extends Tests with TestModule.Munit {

    def ivyDeps = Agg(ivyMunit)
    def testFramework = ivyMunitInterface
  }
}

I have tried versions of mdoc "2.3.3" and the examples "2.2.4" and get the same error. I found this. Can this be an issue with using Scala 3.x? I did find that SBT now works with the version 3 compiler.

EDIT: I also tried it with and without the line

import $ivy.`org.scalameta::mdoc:2.3.3`

but got the same result.

I also looked at the source code and googled and cannot figure out were/how mdoc can set the compiler version. Where is this done here?

TIA

@hmf
Copy link
Author

hmf commented Sep 23, 2022

I have gone a little further on and found that the scala library is downloaded here and the mdoc dependency is also defined. This last line means that that dependency should be in the class path to work. With the build script above, the mdoc library and its transitive dependencies are not available.

So to get the Jvm.runLocal("mdoc.Main", cp, dirParams) to execute correctly I had to use:

  override def ivyDeps = Agg(
      ivy"org.tensorflow:tensorflow-core-api:${tensorflowVersion}",
      ivy"org.tensorflow:tensorflow-core-api:${tensorflowVersion};classifier=${javaCPPPlatform()}"
  ) ++ super[MDocModule].ivyDeps() // scalaMdocDep()

EDIT:
I am using Mill 0.10.7. Shouldn't these dependencies be added automatically? If not, then the I think the example in the README should be changed slightly to add the dependency.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant