Следующий проект компилируется
build.sc
import mill._, scalalib._
object root extends ScalaModule {
def scalaVersion = "2.13.1"
val zioMacrosV = "0.4.0"
def ivyDeps = Agg(
ivy"dev.zio::zio-macros-core:${zioMacrosV}",
ivy"dev.zio::zio-macros-access:${zioMacrosV}",
ivy"dev.zio::zio-macros-mock:${zioMacrosV}"
)
def scalacOptions = Seq(
"-Ymacro-annotations",
"-Ymacro-debug-lite"
)
}
root / src / App.scala
import zio.ZIO
import zio.macros.access.accessible
import zio.macros.mock.mockable
@accessible
@mockable
trait AccountObserver {
val accountObserver: AccountObserver.Service[Any]
}
object AccountObserver {
trait Service[R] {
def processEvent(event: String): ZIO[R, Nothing, Unit]
}
}
Команда mill root.compile
компилирует проект
//{
// abstract trait AccountObserver extends scala.AnyRef {
// val accountObserver: AccountObserver.Service[Any]
// };
// object AccountObserver extends scala.AnyRef {
// def <init>() = {
// super.<init>();
// ()
// };
// abstract trait Service[R] extends scala.AnyRef {
// def processEvent(event: String): ZIO[R, Nothing, Unit]
// };
// object Service extends scala.AnyRef {
// def <init>() = {
// super.<init>();
// ()
// };
// case object processEvent extends _root_.zio.test.mock.Method[String, Unit] with scala.Product with scala.Serializable {
// def <init>() = {
// super.<init>();
// ()
// }
// }
// };
// implicit val mockable: _root_.zio.test.mock.Mockable[AccountObserver] = ((mock: _root_.zio.test.mock.Mock) => {
// final class $anon extends AccountObserver {
// def <init>() = {
// super.<init>();
// ()
// };
// val accountObserver = {
// final class $anon extends Service[Any] {
// def <init>() = {
// super.<init>();
// ()
// };
// def processEvent(event: String): _root_.zio.IO[Nothing, Unit] = mock(Service.processEvent, event)
// };
// new $anon()
// }
// };
// new $anon()
// });
// object $greater extends Service[AccountObserver] {
// def <init>() = {
// super.<init>();
// ()
// };
// def processEvent(event: String): _root_.zio.IO[Nothing, Unit] = _root_.zio.ZIO.accessM(<empty> match {
// case (env @ (_: AccountObserver)) => env.accountObserver.processEvent(event)
// })
// }
// };
// ()
//}
Создает файлы IntelliJ
mill mill.scalalib.GenIdea/idea
, а затем открывает проект в IntelliJ (не import it).
Теперь Ctrl + Shift + F9 компилирует проект (аналогично описанному выше).
Вы можете использовать, например, ссылку на объект AccountObserver.Service
(компилируется). Конечно, IntelliJ выделяет Service
красным, но это не имеет значения.