Skip to content

Commit

Permalink
Merge pull request #11 from viktor-podzigun/fix_10_migrate_to_sbt_1_x
Browse files Browse the repository at this point in the history
Migrated to sbt 1.x, fixed #10
  • Loading branch information
axel22 authored Jan 17, 2021
2 parents 6d277d9 + 33d1b0f commit e936b9b
Show file tree
Hide file tree
Showing 30 changed files with 243 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .gitignore-SAMPLE → .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

# idea
.idea
*.iml

# configuration files
config.sbt

# workflow stuff
.gitignore
target
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ before_script:
export SSH_KEY_PASS=""
export DISPLAY=""
- |
mkdir -p ~/.sbt/0.13/
echo 'scalacOptions ++= Seq("-Xmax-classfile-name", "90")' > ~/.sbt/0.13/local.sbt
mkdir -p ~/.sbt/1.0/
echo 'scalacOptions ++= Seq("-Xmax-classfile-name", "90")' > ~/.sbt/1.0/local.sbt
- git clone git@ci.storm-enroute.com:storm-enroute/super-storm-enroute.git ~/.super-storm-enroute

after_script:
Expand Down
18 changes: 15 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
language: scala
sudo: false
scala:
- "2.10.7"
- "2.12.1"
jdk:
- oraclejdk7
script: sbt ++${TRAVIS_SCALA_VERSION} test publishM2 scripted
- oraclejdk8
dist: trusty
script:
- sbt ++${TRAVIS_SCALA_VERSION} test publishM2 scripted
env:
global:
- TRAVIS_SBT_VERSION="1.2.8"
- secure: "adngy4wHe+DLnkLW0K7S8KFe+GR2mTMHx3VPs4YFooXSkJlRZMzhMzd2nJN0VNb2U7zkIrtLvsykLGIaeKF3u02iheHt3RCpRoKmxOjAkFXSRm6V7Z1J+EMVHqAG/72L2P2KkjJEaXrQqE3yG6e6elRk+qp2V3zKpQ6E5sS/g3c="
- secure: "fjMyfWi+UndcsT+Voqxt1NVvIbqPKwDzipxK18zd+eEgASam+L4fgtmDsIXjbgdBaTX59w+Q1DNnAOT7x34XpneU+GDASDmoNdj6oCoZOHiQb/odu2WOBWf/iINCTpJtPMMr8cLQaQ3CsnSyOojaJiFERDMcO9i58kDfU1gXa/4="
branches:
only:
- master
notifications:
slack: storm-enroute:GnbA8DEy3mL3Pyp3cbptr7F2
cache:
directories:
- "$HOME/.ivy2/cache"
- "$HOME/.sbt"
before_cache:
# Cleanup the cached directories to avoid unnecessary cache updates
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete
- find $HOME/.sbt -name "*.lock" -print -delete
54 changes: 30 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,28 @@ Create the `project/plugins.sbt` file and at the following:
3. Define a super-repo build in `project/Build.scala` as in the following example:

object MechaSuperRepoBuild extends MechaSuperBuild {
lazy val mechaSuperRepoSettings = Defaults.defaultSettings ++
defaultMechaSuperSettings ++ Seq(

def definition(): Project = superProject

lazy val mechaSuperRepoSettings = defaultMechaSuperSettings ++ Seq(
name := superName,
scalaVersion := "2.11.4",
scalaVersion := "2.12.1",
version := "0.1",
organization := "com.storm-enroute",
libraryDependencies ++= Seq()
)
val superName = "super-storm-enroute"
val superDirectory = file(".")
val superSettings = mechaSuperRepoSettings
override val superName = "super-storm-enroute"
override val superSettings = mechaSuperRepoSettings
}

The values of particular importance here are `superName`, `superDirectory` and
`superSettings`.
You don't need to define a project when you define a super-repo.
The project is automatically defined for you from these three values.
The values of particular importance here are `superName` and `superSettings`.

4. Reference build definition from `build.sbt` as in the following example:

4. Last, create a `repos.conf` file in the super-repo root directory.
lazy val `super-storm-enroute` = MechaSuperRepoBuild.definition()

5. Last, create a `repos.conf` file in the super-repo root directory.
This file contains information about subprojects in this super-repo.
Initially, we can just add the super-project to it:

Expand Down Expand Up @@ -469,10 +471,10 @@ We first need to convert the `examples-application` build into a Mecha repo buil
import sbt.Keys._
object ExamplesApplicationBuild extends MechaRepoBuild {
lazy val examplesApplicationSettings = Defaults.defaultSettings ++
MechaRepoPlugin.defaultSettings ++ Seq(

lazy val examplesApplicationSettings = MechaRepoPlugin.defaultSettings ++ Seq(
name := "examples-application",
scalaVersion := "2.11.4",
scalaVersion := "2.12.1",
version := "0.1",
organization := "com.storm-enroute",
libraryDependencies ++=
Expand All @@ -483,18 +485,22 @@ We first need to convert the `examples-application` build into a Mecha repo buil

lazy val examplesApplication: Project = Project(
"examples-application",
file("."),
settings = examplesApplicationSettings
) dependsOnSuperRepo
file(".")
).settings(
examplesApplicationSettings
).dependsOnSuperRepo
}

Here, the crucial part is the `dependsOnSuperRepo` --
**don't forget to add this or the dependencies won't be picked up!**
The other crucial part is `libraryDependencies ++= superRepoDependencies`.
For `repoName`, use the same name as in the `repos.conf` file from the super-repo.

3. Reference build definition from `build.sbt` as in the following example:

lazy val `examples-application` = ExamplesApplicationBuild.examplesApplication

3. Run `reload` in the SBT shell and you've got a Mecha repo build.
4. Run `reload` in the SBT shell and you've got a Mecha repo build.

The `examples-application` can now do various powerful stuff.
Let's get back to our config files.
Expand Down Expand Up @@ -661,10 +667,9 @@ Here is an example project build setup, in `project/Build.scala`:

object ExamplesApplicationBuild extends MechaProjectBuild {

lazy val examplesApplicationSettings = Defaults.defaultSettings ++
MechaRepoPlugin.defaultSettings ++ Seq(
lazy val examplesApplicationSettings = MechaRepoPlugin.defaultSettings ++ Seq(
name := "examples-application",
scalaVersion := "2.11.4",
scalaVersion := "2.12.1",
version := "0.1",
organization := "com.storm-enroute",

Expand Down Expand Up @@ -692,9 +697,10 @@ Here is an example project build setup, in `project/Build.scala`:

lazy val examplesApplication: Project = Project(
"examples-application",
file("."),
settings = examplesApplicationSettings
) dependsOnSuperRepo
file(".")
).settings(
examplesApplicationSettings
).dependsOnSuperRepo
}

Here, the crucial parts are:
Expand Down
102 changes: 79 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,25 +1,81 @@

// set environment variables to publish
// in newer SBT versions, this apparently has to go to `build.sbt`
import java.io._

{
val publishUser = "SONATYPE_USER"
val publishPass = "SONATYPE_PASS"
val userPass = for {
user <- sys.env.get(publishUser)
pass <- sys.env.get(publishPass)
} yield (user, pass)
val publishCreds: Seq[Setting[_]] = Seq(userPass match {
case Some((user, pass)) =>
println(s"Username and password for Sonatype picked up: '$user', '${if (pass != "") "******" else ""}'")
credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", user, pass)
case None =>
// prevent publishing
val errorMessage =
"Publishing to Sonatype is disabled since the \"" +
publishUser + "\" and/or \"" + publishPass + "\" environment variables are not set."
println(errorMessage)
publish <<= streams.map(_.log.info(errorMessage))
})
publishCreds
}
val ideExcludedDirectories = SettingKey[Seq[File]]("ide-excluded-directories")

lazy val mecha = (project in file("."))
.enablePlugins(SbtPlugin)
.settings(
scriptedLaunchOpts := { scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-XX:MaxPermSize=256M", "-Dplugin.version=" + version.value)
},
scriptedBufferLog := false
)
.settings(
sbtPlugin := true,
name := "mecha",
scalaVersion := "2.12.1",
version := {
def versionFromFile(filename: String): String = {
val fis = new FileInputStream(filename)
val props = new java.util.Properties()
try props.load(fis)
finally fis.close()

val major = props.getProperty("mecha_major")
val minor = props.getProperty("mecha_minor")
s"$major.$minor"
}

versionFromFile(baseDirectory.value + File.separator + "version.conf")
},
organization := "com.storm-enroute",
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.2.1",
"commons-io" % "commons-io" % "2.4",
"com.decodified" %% "scala-ssh" % "0.8.0",
"com.github.pathikrit" %% "better-files" % "2.17.1",
//test
"org.specs2" %% "specs2-core" % "3.8.6" % "test",
"org.specs2" %% "specs2-junit" % "3.8.6" % "test",
"junit" % "junit" % "4.12" % "test"
),
ideExcludedDirectories := {
val base = baseDirectory.value
List(
base / ".idea",
base / "target"
)
},
publishMavenStyle := true,
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
pomExtra := {
<url>http://storm-enroute.com/</url>
<licenses>
<license>
<name>BSD-style</name>
<url>http://opensource.org/licenses/BSD-3-Clause</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git@github.com:storm-enroute/mecha.git</url>
<connection>scm:git:git@github.com:storm-enroute/mecha.git</connection>
</scm>
<developers>
<developer>
<id>axel22</id>
<name>Aleksandar Prokopec</name>
<url>http://axel22.github.com/</url>
</developer>
</developers>
}
)
2 changes: 1 addition & 1 deletion cross.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.10.7
2.12.1
90 changes: 0 additions & 90 deletions project/Build.scala

This file was deleted.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.17
sbt.version=1.2.8
4 changes: 1 addition & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.1")

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
2 changes: 0 additions & 2 deletions project/scripted.sbt

This file was deleted.

12 changes: 12 additions & 0 deletions project/sonatype.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

val maybeCredentials = for {
username <- Option(System.getenv().get("SONATYPE_USER"))
password <- Option(System.getenv().get("SONATYPE_PASS"))
} yield Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
username,
password
)

credentials ++= maybeCredentials.toSeq
Loading

0 comments on commit e936b9b

Please sign in to comment.