From dc41753da8b6eea9e0c16f332cf90e68647f108a Mon Sep 17 00:00:00 2001 From: Fernando Racca Date: Sun, 19 Nov 2017 19:50:08 +0000 Subject: [PATCH] Simple multi module SBT project with native packager plugin for deployment. --- .gitignore | 15 +++++ README.md | 32 ++++++++++ app/src/main/resources/logback.xml | 18 ++++++ .../fractal/mpskeleton/app/Application.scala | 15 +++++ build.sbt | 60 +++++++++++++++++++ .../mpskeleton/common/KafkaConfig.scala | 9 +++ .../mpskeleton/kafka/DummyKafkaConsumer.scala | 15 +++++ .../kafka/SimpleKafkaConsumer.scala | 15 +++++ project/Dependencies.scala | 29 +++++++++ project/build.properties | 1 + project/plugins.sbt | 9 +++ 11 files changed, 218 insertions(+) create mode 100755 .gitignore create mode 100755 README.md create mode 100644 app/src/main/resources/logback.xml create mode 100644 app/src/main/scala/com/github/fractal/mpskeleton/app/Application.scala create mode 100755 build.sbt create mode 100644 common/src/main/scala/com/github/fractal/mpskeleton/common/KafkaConfig.scala create mode 100644 kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/DummyKafkaConsumer.scala create mode 100644 kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/SimpleKafkaConsumer.scala create mode 100644 project/Dependencies.scala create mode 100755 project/build.properties create mode 100644 project/plugins.sbt diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..882c3cb --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +#SBT +target + +# Mac +.DS_Store + +# IntelliJ +.idea +.idea_modules +*.iml +*.ipr +*.iws +.history + +project/target \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..284d8d8 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +Multi-Project-Skeleton +------------ + +This project aims to simplify creating a multi module project ready to package and deploy to a server. + +It provides some minimal code just to demonstrate usage. + +Requires +--------------- +* Please download latest version of SBT. +* [sbt 1.0.3](http://www.scala-sbt.org) + +Use +--------------- +Clone and update the project name from build.sbt + + $ git clone git://github.com/fractal/multi-project-skeleton my-project + $ cd my-project + $ rm -rf .git + $ vi build.sbt # change name to my-project, and organization to something that suits you + $ sbt + > app/run + > app/packageZipTarball + +Author +-------------------- +Fernando Racca + +[@quant_leap](http://twitter.com/quant_leap) + +Simpler version: +[fractal/skeleton](http://github.com/fractal/skeleton) diff --git a/app/src/main/resources/logback.xml b/app/src/main/resources/logback.xml new file mode 100644 index 0000000..7ea7c0c --- /dev/null +++ b/app/src/main/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/scala/com/github/fractal/mpskeleton/app/Application.scala b/app/src/main/scala/com/github/fractal/mpskeleton/app/Application.scala new file mode 100644 index 0000000..fd655c2 --- /dev/null +++ b/app/src/main/scala/com/github/fractal/mpskeleton/app/Application.scala @@ -0,0 +1,15 @@ +package com.github.fractal.mpskeleton.app + +import com.github.fractal.mpskeleton.common.KafkaConfig +import com.github.fractal.mpskeleton.kafka.DummyKafkaConsumer + +object Application extends App { + + val kafkaConsumer = DummyKafkaConsumer(SimpleKafkaConfig()) + + kafkaConsumer.consume() + +} + + +case class SimpleKafkaConfig(topic : String = "dummyTopic") extends KafkaConfig \ No newline at end of file diff --git a/build.sbt b/build.sbt new file mode 100755 index 0000000..1ce5f5c --- /dev/null +++ b/build.sbt @@ -0,0 +1,60 @@ + +name := "multi-project-skeleton" + +import Dependencies._ + +// For Settings/Task reference, see http://www.scala-sbt.org/release/sxr/sbt/Keys.scala.html + +lazy val common = (project in file("common")).settings(commonSettings) + +lazy val kafka = (project in file("kafka")).settings(kafkaSettings).dependsOn(common) + +lazy val app = (project in file("app")). + settings(appSettings). + dependsOn(kafka). + dependsOn(common). + enablePlugins(UniversalPlugin). + enablePlugins(JavaAppPackaging) + +lazy val root = Project( + id = "root", + base = file(".") +).aggregate(common, kafka, app) + .settings(Defaults.coreDefaultSettings ++ dontPublishRootModuleSettings) + +lazy val generalModuleSettings = Seq( + organization := "com.github.fractal", + version := "1.4", + scalaVersion := "2.12.4", + // Compiler settings. Use scalac -X for other options and their description. + // See Here for more info http://www.scala-lang.org/files/archive/nightly/docs/manual/html/scalac.html + scalacOptions ++= List("-feature","-deprecation", "-unchecked", "-Xlint"), + + // Uncommenting this line sometime helps troubleshooting if you are having issues with jars download (for example, if behind a proxy) + //ivyLoggingLevel := UpdateLogging.Full + publishArtifact in Test := false, + publishTo := { + val basePublishingUrl = "http://internal-repo/" //your proxy reporsitory url + val suffix = if(isSnapshot.value) "snapshots" else "releases" + val internalRepoBaseName = "internal-repo" + Some(s"$internalRepoBaseName-$suffix" at (basePublishingUrl + suffix)) + } +) + +lazy val dontPublishRootModuleSettings = Seq( + publishLocal := {}, + publish := {} +) + + +lazy val commonSettings = generalModuleSettings ++ Seq( + libraryDependencies ++= commonDependencies +) + +lazy val kafkaSettings = generalModuleSettings ++ Seq( + libraryDependencies ++= kafkaDependencies +) + +lazy val appSettings = generalModuleSettings ++ Seq( + libraryDependencies ++= appDependencies +) diff --git a/common/src/main/scala/com/github/fractal/mpskeleton/common/KafkaConfig.scala b/common/src/main/scala/com/github/fractal/mpskeleton/common/KafkaConfig.scala new file mode 100644 index 0000000..59403fc --- /dev/null +++ b/common/src/main/scala/com/github/fractal/mpskeleton/common/KafkaConfig.scala @@ -0,0 +1,9 @@ +package com.github.fractal.mpskeleton.common + + +trait KafkaConfig { + + def topic: String + +} + diff --git a/kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/DummyKafkaConsumer.scala b/kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/DummyKafkaConsumer.scala new file mode 100644 index 0000000..3aa224e --- /dev/null +++ b/kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/DummyKafkaConsumer.scala @@ -0,0 +1,15 @@ +package com.github.fractal.mpskeleton.kafka + +import com.github.fractal.mpskeleton.common.KafkaConfig + +case class DummyKafkaConsumer(kafkaConfig: KafkaConfig) { + + import KafkaConsumer.logger + + def consume(): Unit = { + val topic = kafkaConfig.topic + + logger.info(s"[Consumer] @ $topic ") + } + +} diff --git a/kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/SimpleKafkaConsumer.scala b/kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/SimpleKafkaConsumer.scala new file mode 100644 index 0000000..bd39899 --- /dev/null +++ b/kafka/src/main/scala/com/github/fractal/mpskeleton/kafka/SimpleKafkaConsumer.scala @@ -0,0 +1,15 @@ +package com.github.fractal.mpskeleton.kafka + +import com.github.fractal.mpskeleton.common.KafkaConfig +import org.slf4j.LoggerFactory + + +trait SimpleKafkaConsumer { + def kafkaConfig: KafkaConfig +} + + +object KafkaConsumer { + + val logger = LoggerFactory.getLogger(KafkaConsumer.getClass) +} \ No newline at end of file diff --git a/project/Dependencies.scala b/project/Dependencies.scala new file mode 100644 index 0000000..7146168 --- /dev/null +++ b/project/Dependencies.scala @@ -0,0 +1,29 @@ + +import sbt._ + +object Dependencies extends Versions { + + lazy val commonDependencies = Seq( + "org.slf4j" % "slf4j-api" % slf4jVersion, + "org.scalatest" %% "scalatest" % scalaTestVersion % "test" + ) + + lazy val kafkaDependencies = Seq( + "org.slf4j" % "slf4j-api" % slf4jVersion, + "org.scalatest" %% "scalatest" % scalaTestVersion % "test" + ) + + + lazy val appDependencies = Seq( + "ch.qos.logback" % "logback-classic" % "1.2.3", + "org.scalatest" %% "scalatest" % scalaTestVersion % "test" + ) + +} + +trait Versions { + + lazy val slf4jVersion = "1.7.25" + lazy val scalaTestVersion = "3.0.4" + +} \ No newline at end of file diff --git a/project/build.properties b/project/build.properties new file mode 100755 index 0000000..9abea12 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.0.3 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..eb760d8 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,9 @@ +resolvers += Classpaths.sbtPluginReleases + +// See docs : https://github.com/sbt/sbt-native-packager +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.1") +//Documentation is not published, which can cause some issues when using Intellij's SBT Shell Library + + +//just a useful tool graph depenency tool. comment out if having troubles behind certain proxies +//addSbtPlugin("net-virtual-void" % "sbt-dependency-graph" % "0.9.0") \ No newline at end of file