Skip to content

Commit

Permalink
Simple multi module SBT project with native packager plugin for deplo…
Browse files Browse the repository at this point in the history
…yment.
  • Loading branch information
fernandoracca committed Nov 19, 2017
1 parent f1362a3 commit dc41753
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#SBT
target

# Mac
.DS_Store

# IntelliJ
.idea
.idea_modules
*.iml
*.ipr
*.iws
.history

project/target
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions app/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>

<logger name="com.github.fractal.mpskeleton" level="debug" />

<root level="info">
<appender-ref ref="STDOUT" />
</root>

</configuration>
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.fractal.mpskeleton.common


trait KafkaConfig {

def topic: String

}

Original file line number Diff line number Diff line change
@@ -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 ")
}

}
Original file line number Diff line number Diff line change
@@ -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)
}
29 changes: 29 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -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"

}
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.0.3
9 changes: 9 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit dc41753

Please sign in to comment.