Home > Enterprise >  How to define withSources and/or withJavadoc in mill ivyDeps
How to define withSources and/or withJavadoc in mill ivyDeps

Time:09-17

If you want to load module sources and/or javadocs you write following sbt:

lazy val joda_timeV = "1.2.3" 
lazy val scalatagsV = "1.2.3" 
lazy val upickleV = "1.2.4" 
lazy val autowireV = "1.2.5" 
lazy val scalarxV = "1.2.6" 


libraryDependencies   = Seq( 
  "joda-time" % "joda-time" % joda_timeV withJavadoc(), 
  "com.lihaoyi" %%% "scalatags" % scalatagsV withSources() withJavadoc(),   
  "com.lihaoyi" %% "upickle" % upickleV withSources() withJavadoc(),
  "com.lihaoyi" %%% "autowire" % autowireV withJavadoc(),
  "com.lihaoyi" %%% "scalarx" % scalarxV  withSources(),
  "org.scalatestplus.play" %% "scalatestplus-play" % scalatestplus_playV % "test" withSources() withJavadoc() 
),

In mill you say

override def ivyDeps = Agg(
    ivy"joda-time:joda-time:${joda_timeV}", 
    ivy"com.lihaoyi:::scalatags:${scalatagsV}", 
    ivy"com.lihaoyi::upickle:${upickleV}",
    ivy"com.lihaoyi:::autowire:${autowireV}",
    ivy"com.lihaoyi:::scalarx:${scalarxV}"
)

but how can you add withJavadoc() or withSources() or withSources() withJavadoc() in to mill build.sc? There is function .withConfiguration(String) but no scaladoc how to use it.

Is it possible to define that a module is available only in test (like org.scalatestplus.play in the previous code) or should I create separate ivyDeps for testing module?

CodePudding user response:

Regarding your first question, I assume, your are interested in good IDE support, e.g. completion and jump-to the sources of your dependencies.

Mill already supports IDE integration. It comes with a project generator for IntelliJ IDEA (mill mill.scalalib.GenIdea/idea), which automatically downloads the sources for you. Alternatively, you can use the new BSP Support (Build Server Protocol) which should in combination with the Metals Language Server (https://scalameta.org/metals/) provide a nice editing experience in various IDEs and Editors. Unfortunately, at the time of this writing, Mills built-in BSP server isn't as robust as its IDEA generator, but there is even another alternative, the Bloop contrib module. All these methods should provide decent code navigation through dependencies and completion.

And to your second question:

Is it possible to define that a module is available only in test (like org.scalatestplus.play in the previous code) or should I create separate ivyDeps for testing module?

Test dependencies are declared it the test modules (which are technically regular modules too).

// build.sc
// ...

object yourplaymodule extends PlayModule {
  override def ivyDeps = Agg(
    ivy"joda-time:joda-time:${joda_timeV}", 
    ivy"com.lihaoyi:::scalatags:${scalatagsV}", 
    ivy"com.lihaoyi::upickle:${upickleV}",
    ivy"com.lihaoyi:::autowire:${autowireV}",
    ivy"com.lihaoyi:::scalarx:${scalarxV}"
  )
  // ...
  object test extends PlayTests {
    override def ivyDeps = Agg(
      ivy"org.scalatestplus.play::scalatestplus-play:${scalatestplus_playV}"
    )
  }
}

Edit 2021-09-16: Added the answer to the first question.

  • Related