Scala SBT project to create several modules for launch cans

I am having problems creating and running an SBT project.

  • The protocol project is used by several modules, including the daemon.

  • The demon project must be packaged as an executable jar.

What is the β€œright” way to do this?

Here is my build.scala:

object MyBuild extends Build { lazy val buildSettings = Seq( organization := "com.example", version := "1.0-SNAPSHOT", scalaVersion := "2.9.1" ) lazy val root = Project( id = "MyProject", base = file("."), aggregate = Seq(protocol, daemon) ) lazy val protocol = Project( id = "Protocol", base = file("Protocol") ) lazy val daemon = Project( id = "Daemon", base = file("Daemon"), dependencies = Seq(protocol) ) // (plus more projects) 
+6
source share
1 answer

The right way to do this is to use one of the sbt plugins to create jars. I tested both single-jar and assembly and both have support for excluding libraries from your jar. You can add settings to individual projects so that only some of them create banks.

I personally use assembly, but as this post indicates, you will run into problems if you have overlapping file names.

Edit:

In the above example, you added the following imports at the top:

 import sbtassembly.Plugin._ import AssemblyKeys._ 

You would modify the project this way:

 lazy val daemon = Project( id = "Daemon", base = file("Daemon"), dependencies = Seq(protocol), settings = assemblySettings ) 

Also you need to add the following to project/plugins.sbt (for sbt.11):

 addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.3") resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns) 

If you decide to go with Assembly, you probably need to remove duplicate files. Here is an example build code to avoid duplicate log4j.properties files in a project named "projectName". This should be added as part of the settings sequence for the project. Please note that the second compilation is a basic implementation and is required.

 excludedFiles in assembly := { (bases: Seq[File]) => bases.filterNot(_.getAbsolutePath.contains("projectName")) flatMap { base => //Exclude all log4j.properties from other peoples jars ((base * "*").get collect { case f if f.getName.toLowerCase == "log4j.properties" => f }) ++ //Exclude the license and manifest from the exploded jars ((base / "META-INF" * "*").get collect { case f if f.getName.toLowerCase == "license" => f case f if f.getName.toLowerCase == "manifest.mf" => f }) } } 
+7
source

Source: https://habr.com/ru/post/911106/


All Articles