sbt.plugins.JvmPlugin Scala Examples

The following examples show how to use sbt.plugins.JvmPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: Common.scala    From spark-benchmarks   with Apache License 2.0 5 votes vote down vote up
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import de.heikoseeberger.sbtheader._
import de.heikoseeberger.sbtheader.license.Apache2_0
import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin

object Common extends AutoPlugin {

  override def trigger = allRequirements

  override def requires = JvmPlugin && AutomateHeaderPlugin

  override lazy val projectSettings =
    Dependencies.Common ++ Seq(
      organization := "com.bbva.spark",
      organizationName := "BBVA",
      version := "0.1.0",
      organizationHomepage := Some(url("https://github.com/BBVA")),
      scmInfo := Some(ScmInfo(url("https://github.com/BBVA/spark-benchmarks"), "[email protected]:BBVA/spark-benchmarks.git")),
      developers += Developer("contributors", "Contributors", "", url("https://github.com/BBVA/spark-benchmarks/contributors")),

      licenses := Seq(("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0"))),

      scalaVersion := Dependencies.ScalaVersion,

      scalacOptions ++= Seq(
        "-encoding", "UTF-8",
        "-feature",
        "-unchecked",
        "-deprecation",
        //"-Xfatal-warnings",
        "-Xlint",
        "-Yno-adapted-args",
        "-Ywarn-dead-code",
        "-Xfuture"
      ),

      javacOptions ++= Seq(
        "-Xlint:unchecked"
      ),

      //autoAPIMappings := true,
      //apiURL := Some(url(s"http://developer.bbva.com/docs/api/spark-benchmarks/${version.value}")),

      headers := headers.value ++ Map(
        "scala" -> Apache2_0("2017", "Banco Bilbao Vizcaya Argentaria S.A."),
        "java" -> Apache2_0("2017", "Banco Bilbao Vizcaya Argentaria S.A."),
        "conf" -> Apache2_0("2017", "Banco Bilbao Vizcaya Argentaria S.A.", "#")
      )
    )

} 
Example 2
Source File: Common.scala    From play-soap   with Apache License 2.0 5 votes vote down vote up
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin
import Dependencies.ScalaVersions._
import de.heikoseeberger.sbtheader.HeaderPlugin

object Common extends AutoPlugin {

  import HeaderPlugin.autoImport._

  override def trigger = allRequirements

  override def requires = JvmPlugin && HeaderPlugin

  val repoName = "play-soap"

  override def globalSettings =
    Seq(
      // organization
      organization := "com.typesafe.play",
      organizationName := "Lightbend Inc.",
      organizationHomepage := Some(url("https://www.lightbend.com/")),
      // scala settings
      scalaVersion := scala212,
      scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-encoding", "utf8"),
      javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:-options"),
      // legal
      licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")),
      // on the web
      homepage := Some(url(s"https://github.com/playframework/${repoName}")),
      scmInfo := Some(
        ScmInfo(
          url(s"https://github.com/playframework/${repoName}"),
          s"scm:git:[email protected]:playframework/${repoName}.git"
        )
      ),
      developers += Developer(
        "contributors",
        "Contributors",
        "https://gitter.im/playframework/contributors",
        url("https://github.com/playframework")
      )
    )

  override def projectSettings =
    Seq(
      headerEmptyLine := false,
      headerLicense := Some(HeaderLicense.Custom("Copyright (C) Lightbend Inc. <https://www.lightbend.com>"))
    )
} 
Example 3
Source File: Common.scala    From akka-persistence-cassandra   with Apache License 2.0 5 votes vote down vote up
import bintray.BintrayPlugin.autoImport._
import com.lightbend.paradox.projectinfo.ParadoxProjectInfoPluginKeys._
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import de.heikoseeberger.sbtheader._
import org.scalafmt.sbt.ScalafmtPlugin.autoImport._
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin

object Common extends AutoPlugin {

  override def trigger = allRequirements

  override def requires = JvmPlugin && HeaderPlugin

  override def globalSettings =
    Seq(
      organization := "com.typesafe.akka",
      organizationName := "Lightbend Inc.",
      organizationHomepage := Some(url("https://www.lightbend.com/")),
      startYear := Some(2016),
      homepage := Some(url("https://akka.io")),
      // apiURL defined in projectSettings because version.value is not correct here
      scmInfo := Some(
          ScmInfo(
            url("https://github.com/akka/akka-persistence-cassandra"),
            "[email protected]:akka/akka-persistence-cassandra.git")),
      developers += Developer(
          "contributors",
          "Contributors",
          "https://gitter.im/akka/dev",
          url("https://github.com/akka/akka-persistence-cassandra/graphs/contributors")),
      licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))),
      description := "A Cassandra plugin for Akka Persistence.")

  override lazy val projectSettings = Seq(
    projectInfoVersion := (if (isSnapshot.value) "snapshot" else version.value),
    crossVersion := CrossVersion.binary,
    crossScalaVersions := Dependencies.ScalaVersions,
    scalaVersion := Dependencies.Scala212,
    scalacOptions ++= Seq("-encoding", "UTF-8", "-feature", "-unchecked", "-Xlint", "-Ywarn-dead-code", "-deprecation"),
    Compile / console / scalacOptions --= Seq("-deprecation", "-Xfatal-warnings", "-Xlint", "-Ywarn-unused:imports"),
    Compile / doc / scalacOptions := scalacOptions.value ++ Seq(
        "-doc-title",
        "Akka Persistence Cassandra",
        "-doc-version",
        version.value,
        "-sourcepath",
        (baseDirectory in ThisBuild).value.toString,
        "-doc-source-url", {
          val branch = if (isSnapshot.value) "master" else s"v${version.value}"
          s"https://github.com/akka/akka-persistence-cassandra/tree/${branch}€{FILE_PATH_EXT}#L€{FILE_LINE}"
        },
        "-skip-packages",
        "akka.pattern" // for some reason Scaladoc creates this
      ),
    Compile / doc / scalacOptions --= Seq("-Xfatal-warnings"),
    scalafmtOnCompile := true,
    autoAPIMappings := true,
    apiURL := Some(url(s"https://doc.akka.io/api/akka-persistence-cassandra/${projectInfoVersion.value}")),
    headerLicense := Some(
        HeaderLicense.Custom("""Copyright (C) 2016-2020 Lightbend Inc. <https://www.lightbend.com>""")),
    Test / logBuffered := System.getProperty("akka.logBufferedTests", "false").toBoolean,
    // show full stack traces and test case durations
    Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oDF"),
    // -a Show stack traces and exception class name for AssertionErrors.
    // -v Log "test run started" / "test started" / "test run finished" events on log level "info" instead of "debug".
    // -q Suppress stdout for successful tests.
    Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-q"),
    Test / parallelExecution := false,
    bintrayOrganization := Some("akka"),
    bintrayPackage := "akka-persistence-cassandra",
    bintrayRepository := (if (isSnapshot.value) "snapshots" else "maven"))
} 
Example 4
Source File: Build.scala    From scalalaz-gen   with Apache License 2.0 5 votes vote down vote up
import com.typesafe.sbt.GitPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin
import org.scalafmt.sbt._
import play.twirl.sbt.SbtTwirl
import sbt._
import sbt.plugins.JvmPlugin
import sbt.Keys._

object Build extends AutoPlugin {

  override def requires = JvmPlugin && GitPlugin&& HeaderPlugin && SbtTwirl

  override def trigger = allRequirements

  override def projectSettings =
    Vector(
      // Core settings
      organization := "ru",
      licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
      mappings.in(Compile, packageBin) += baseDirectory.in(ThisBuild).value / "LICENSE" -> "LICENSE",
      scalaVersion := Version.Scala,
      crossScalaVersions := Vector(scalaVersion.value),
      scalacOptions ++= Vector(
        "-unchecked",
        "-deprecation",
        "-feature",
        "-language:_",
        "-target:jvm-1.8",
        "-encoding",
        "UTF-8"
      ),
      unmanagedSourceDirectories.in(Compile) := Vector(scalaSource.in(Compile).value),
      unmanagedSourceDirectories.in(Test) := Vector(scalaSource.in(Test).value),

      // Git settings
      GitPlugin.autoImport.git.useGitDescribe := true,

      // Header settings
      HeaderPlugin.autoImport.headerLicense := Some(HeaderPlugin.autoImport.HeaderLicense.ALv2("2016", "Scalalaz Podcast Team"))

    )
} 
Example 5
Source File: CommonSettingsPlugin.scala    From seahorse   with Apache License 2.0 5 votes vote down vote up
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.Universal
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin

object CommonSettingsPlugin extends AutoPlugin {
  override def requires = JvmPlugin
  override def trigger = allRequirements

  lazy val OurIT = config("it") extend Test

  lazy val globalResources = file("globalresources").getAbsoluteFile

  override def globalSettings = Seq(
    scalaVersion := "2.11.8"
  )

  override def projectSettings = Seq(
    organization := "ai.deepsense",
    scalacOptions := Seq(
      "-unchecked", "-deprecation", "-encoding", "utf8", "-feature",
      "-language:existentials", "-language:implicitConversions"
    ),
    javacOptions ++= Seq(
      "-source", "1.7",
      "-target", "1.7"
    ),
    resolvers ++= Dependencies.resolvers,
    crossPaths := false,
    unmanagedResourceDirectories in Compile += globalResources,
    unmanagedResourceDirectories in Runtime += globalResources,
    unmanagedResourceDirectories in Test += globalResources
  ) ++ ouritSettings ++ testSettings ++ Seq(
    test := (test in Test).value
  )

  lazy val ouritSettings = inConfig(OurIT)(Defaults.testSettings) ++ inConfig(OurIT) {
    Seq(
      testOptions ++= Seq(
        // Show full stacktraces (F), Put results in target/test-reports
        Tests.Argument(TestFrameworks.ScalaTest, "-oF", "-u", "target/test-reports")
      ),
      javaOptions := Seq(s"-DlogFile=${name.value}"),
      fork := true,
      unmanagedClasspath += baseDirectory.value / "conf"
    )
  }

  lazy val testSettings = inConfig(Test) {
    Seq(
      testOptions := Seq(
        // Put results in target/test-reports
        Tests.Argument(
          TestFrameworks.ScalaTest,
          "-o",
          "-u", "target/test-reports"
        )
      ),
      fork := true,
      javaOptions := Seq(s"-DlogFile=${name.value}"),
      unmanagedClasspath += baseDirectory.value / "conf"
    )
  }

  override def projectConfigurations = OurIT +: super.projectConfigurations
} 
Example 6
Source File: BuildIntegrationPlugin.scala    From DataQuality   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package src.main.scala

import sbt.Keys.onLoadMessage
import sbt.plugins.JvmPlugin
import sbt.{AllRequirements, AutoPlugin, Setting, settingKey}


object BuildIntegrationPlugin extends AutoPlugin {

  // make sure it triggers automatically
  override def trigger = AllRequirements
  override def requires = JvmPlugin

  object autoImport {
    object IntegrationEnv extends Enumeration {
      val dev = Value
    }

    val integrationEnv = settingKey[IntegrationEnv.Value]("the current build integration environment")
  }
  import autoImport._

  override def projectSettings: Seq[Setting[_]] = Seq(
    integrationEnv := {
      sys.props.get("integration")
        .orElse(sys.env.get("BUILD_ENV"))
        .flatMap {
          case "dev" => Some(IntegrationEnv.dev)
          case _ => None
        }
        .getOrElse(IntegrationEnv.dev)
    },
    // give feed back
    onLoadMessage := {
      // depend on the old message as well
      val defaultMessage = onLoadMessage.value
      val env = integrationEnv.value
      s"""|$defaultMessage
          |Running in integration environment: $env""".stripMargin
    }
  )

} 
Example 7
Source File: BuildEnvPlugin.scala    From DataQuality   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package src.main.scala

import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin



object BuildEnvPlugin extends AutoPlugin {

  // make sure it triggers automatically
  override def trigger = AllRequirements
  override def requires = JvmPlugin

  object autoImport {
    object BuildEnv extends Enumeration {
      val Production, Stage, Test, Dev = Value
    }

    val buildEnv = settingKey[BuildEnv.Value]("the current build environment")
  }
  import autoImport._

  override def projectSettings: Seq[Setting[_]] = Seq(
    buildEnv := {
      sys.props.get("env")
        .orElse(sys.env.get("BUILD_ENV"))
        .flatMap {
          case "dev" => Some(BuildEnv.Dev)
          case _ => None
        }
        .getOrElse(BuildEnv.Dev)
    },
    // give feed back
    onLoadMessage := {
      // depend on the old message as well
      val defaultMessage = onLoadMessage.value
      val env = buildEnv.value
      s"""|$defaultMessage
          |Running in build environment: $env""".stripMargin
    }
  )

} 
Example 8
Source File: Common.scala    From akka-grpc   with Apache License 2.0 5 votes vote down vote up
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin
import akka.grpc.Dependencies.Versions.{ scala212, scala213 }
import com.lightbend.paradox.projectinfo.ParadoxProjectInfoPluginKeys.projectInfoVersion
import org.scalafmt.sbt.ScalafmtPlugin.autoImport.scalafmtOnCompile
import com.typesafe.tools.mima.plugin.MimaKeys._

object Common extends AutoPlugin {
  override def trigger = allRequirements

  override def requires = JvmPlugin

  override def globalSettings =
    Seq(
      organization := "com.lightbend.akka.grpc",
      organizationName := "Lightbend Inc.",
      organizationHomepage := Some(url("https://www.lightbend.com/")),
      resolvers += Resolver.sonatypeRepo("staging"),
      homepage := Some(url("https://akka.io/")),
      scmInfo := Some(ScmInfo(url("https://github.com/akka/akka-grpc"), "[email protected]:akka/akka-grpc")),
      developers += Developer(
          "contributors",
          "Contributors",
          "https://gitter.im/akka/dev",
          url("https://github.com/akka/akka-grpc/graphs/contributors")),
      licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
      description := "Akka gRPC - Support for building streaming gRPC servers and clients on top of Akka Streams.")

  val silencerVersion = "1.6.0"
  override lazy val projectSettings = Seq(
    projectInfoVersion := (if (isSnapshot.value) "snapshot" else version.value),
    scalacOptions ++= List(
        "-unchecked",
        "-deprecation",
        "-language:_",
        "-Xfatal-warnings",
        "-Ywarn-unused",
        "-encoding",
        "UTF-8"),
    Compile / scalacOptions ++= Seq(
        // generated code for methods/fields marked 'deprecated'
        "-P:silencer:globalFilters=Marked as deprecated in proto file",
        // generated scaladoc sometimes has this problem
        "-P:silencer:globalFilters=unbalanced or unclosed heading",
        // deprecated in 2.13, but used as long as we support 2.12
        "-P:silencer:globalFilters=Use `scala.jdk.CollectionConverters` instead",
        "-P:silencer:globalFilters=Use LazyList instead of Stream",
        // ignore imports in templates
        "-P:silencer:pathFilters=.*.txt",
        // imports in generated code
        // https://github.com/akka/akka-grpc/issues/1009
        "-P:silencer:lineContentFilters=import akka.grpc.internal.ScalaBidirectionalStreamingRequestBuilder",
        "-P:silencer:lineContentFilters=import akka.grpc.scaladsl.SingleResponseRequestBuilder",
        "-P:silencer:lineContentFilters=import akka.grpc.internal.ScalaUnaryRequestBuilder",
        "-P:silencer:lineContentFilters=import akka.grpc.internal.ScalaServerStreamingRequestBuilder",
        "-P:silencer:lineContentFilters=import akka.grpc.scaladsl.StreamResponseRequestBuilder"),
    javacOptions ++= List("-Xlint:unchecked", "-Xlint:deprecation"),
    Compile / doc / scalacOptions := scalacOptions.value ++ Seq(
        "-doc-title",
        "Akka gRPC",
        "-doc-version",
        version.value,
        "-sourcepath",
        (ThisBuild / baseDirectory).value.toString,
        "-skip-packages",
        "akka.pattern:" + // for some reason Scaladoc creates this
        "templates",
        "-doc-source-url", {
          val branch = if (isSnapshot.value) "master" else s"v${version.value}"
          s"https://github.com/akka/akka-grpc/tree/${branch}€{FILE_PATH_EXT}#L€{FILE_LINE}"
        },
        "-doc-canonical-base-url",
        "https://doc.akka.io/api/akka-grpc/current/"),
    Compile / doc / scalacOptions -= "-Xfatal-warnings",
    apiURL := Some(url(s"https://doc.akka.io/api/akka-grpc/${projectInfoVersion.value}/akka/grpc/index.html")),
    libraryDependencies ++= Seq(
        compilerPlugin(("com.github.ghik" % "silencer-plugin" % silencerVersion).cross(CrossVersion.full)),
        ("com.github.ghik" % "silencer-lib" % silencerVersion % Provided).cross(CrossVersion.full)),
    crossScalaVersions := Seq(scala212, scala213),
    mimaReportSignatureProblems := true,
    scalafmtOnCompile := true)
} 
Example 9
Source File: SbtMavenPlugin.scala    From akka-grpc   with Apache License 2.0 5 votes vote down vote up
package akka.grpc

import java.io.File

import sbt.{ CrossVersion, IO, Logger, ModuleID, ModuleInfo, _ }
import sbt.Keys._
import sbt.plugins.JvmPlugin

import scala.util.Try
import scala.xml.{ Elem, PrettyPrinter, XML }


object SbtMavenPlugin extends AutoPlugin {
  override def trigger = noTrigger

  override def requires = JvmPlugin

  object autoImport {
    val mavenGeneratePluginXml = taskKey[Seq[File]]("Generate the maven plugin xml")
  }

  import autoImport._

  override def projectSettings: Seq[Setting[_]] = inConfig(Compile)(unscopedSettings)

  def unscopedSettings =
    Seq(
      sourceDirectory in mavenGeneratePluginXml := sourceDirectory.value / "maven",
      sources in mavenGeneratePluginXml :=
        Seq((sourceDirectory in mavenGeneratePluginXml).value / "plugin.xml").filter(_.exists()),
      target in mavenGeneratePluginXml := target.value / "maven-plugin-xml",
      managedResourceDirectories += (target in mavenGeneratePluginXml).value,
      mavenGeneratePluginXml := {
        val files = (sources in mavenGeneratePluginXml).value
        val outDir = (target in mavenGeneratePluginXml).value / "META-INF" / "maven"
        IO.createDirectory(outDir)

        val pid = projectID.value
        val pi = projectInfo.value
        val deps = allDependencies.value
        val sv = scalaVersion.value
        val sbv = scalaBinaryVersion.value
        val log = streams.value.log

        val configHash = Seq(pid.toString, pi.toString, deps.toString, sv, sbv).hashCode()
        val cacheFile = streams.value.cacheDirectory / "maven.plugin.xml.cache"
        val cachedHash = Some(cacheFile).filter(_.exists()).flatMap { file => Try(IO.read(file).toInt).toOption }
        val configChanged = cachedHash.forall(_ != configHash)

        val outFiles = files.map { file =>
          val outFile = outDir / file.getName

          if (file.lastModified() > outFile.lastModified() || configChanged) {
            log.info(s"Generating $outFile from template")
            val template = XML.loadFile(file)
            val processed = processTemplate(template, pid, pi, deps, CrossVersion(sv, sbv), log)
            IO.write(outFile, new PrettyPrinter(120, 2).format(processed))
          }
          outFile
        }

        IO.write(cacheFile, configHash.toString)

        outFiles
      },
      resourceGenerators += mavenGeneratePluginXml.taskValue)

  def processTemplate(
      xml: Elem,
      moduleID: ModuleID,
      moduleInfo: ModuleInfo,
      dependencies: Seq[ModuleID],
      crossVersion: ModuleID => ModuleID,
      log: Logger) = {
    // Add project meta data
    val withProjectInfo = Seq(
      "name" -> moduleInfo.nameFormal,
      "description" -> moduleInfo.description,
      "groupId" -> moduleID.organization,
      "artifactId" -> moduleID.name,
      "version" -> moduleID.revision).foldRight(xml) {
      case ((label, value), elem) => prependIfAbsent(elem, createElement(label, value))
    }

    withProjectInfo
  }

  private def createElement(label: String, value: String): Elem =
    <elem>{value}</elem>.copy(label = label)

  private def prependIfAbsent(parent: Elem, elem: Elem) =
    if (parent.child.exists(_.label == elem.label)) {
      parent
    } else {
      parent.copy(child = elem +: parent.child)
    }
} 
Example 10
Source File: PomInclusionPlugin.scala    From chatoverflow   with Eclipse Public License 2.0 5 votes vote down vote up
package org.codeoverflow.chatoverflow.build

import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin


object PomInclusionPlugin extends AutoPlugin {

  // Everything in autoImport will be visible to sbt project files
  // They can set this value to false if they don't want to include their dependencies as a pom file
  object autoImport {
    val includePom = settingKey[Boolean]("Whether to include a pom file inside the jar with all dependencies.")
  }
  import autoImport._

  // We require to have the Compile configuration and the packageBin task to override
  override def requires = JvmPlugin
  override def trigger = allRequirements

  // Adds our custom task before the packageBin task
  override val projectSettings: Seq[Def.Setting[_]] =
    inConfig(Compile)(Seq(
      Compile / packageBin := (Compile / packageBin).dependsOn(addPomToOutput).value
    ))

  // Sets default values
  override def buildSettings: Seq[Def.Setting[_]] = inConfig(Compile)(
    includePom in packageBin := true
  )

  // Just copies the pom resulted by makePom into the directory for compiled classes
  // That way the file will be included in the jar
  private lazy val addPomToOutput = Def.taskDyn {
    if ((includePom in packageBin).value) Def.task {
      val pomFile = (Compile / makePom).value

      IO.copyFile(pomFile, new File((Compile / classDirectory).value, "dependencies.pom"))
    } else
      Def.task {} // if disabled, do nothing
  }
} 
Example 11
Source File: ParserGenerator.scala    From scalingua   with Apache License 2.0 5 votes vote down vote up
import sbt.{Def, _}
import Keys._
import sbt.plugins.JvmPlugin
import scala.sys.process._

object ParserGenerator extends AutoPlugin {
  object autoImport {
    val generateLexer   = taskKey[Seq[File]]("Generate JFlex lexer")
    val generateParser  = taskKey[Seq[File]]("Generate CUP parser")
  }

  import autoImport._

  override def requires = JvmPlugin

  override def projectSettings: Seq[Def.Setting[_]] =
    inConfig(Compile)(configurationSettings) ++ inConfig(Test)(configurationSettings)

  private def generationSettings(extension: String, dir: String, task: TaskKey[Seq[File]]): Seq[Def.Setting[_]] = Seq(
    sourceDirectories in task := Seq(sourceDirectory.value),
    includeFilter in task := extension,
    excludeFilter in task := HiddenFileFilter,

    sources in task :=
      Defaults.collectFiles(sourceDirectories in task, includeFilter in task, excludeFilter in task).value,

    target in task := crossTarget.value / dir,

    sourceGenerators += task.taskValue,
    managedSourceDirectories += (target in task).value
  )

  private def configurationSettings: Seq[Def.Setting[_]] =
    generationSettings("*.flex", "generated-lexer", generateLexer) ++
    generationSettings("*.cup", "generated-parser", generateParser) ++
    Seq(
      generateLexer := generateLexerTask.value,
      generateParser := generateParserTask.value
    )

  private def runJava(mainClass: Class[_], args: String*): Unit = {
    val loc = new File(mainClass.getProtectionDomain.getCodeSource.getLocation.toURI).getCanonicalPath
    val cmdline = Seq("java", "-cp", loc, mainClass.getName) ++ args
    val exitCode = cmdline.!
    if (exitCode != 0)
      throw new RuntimeException(s"Process '${cmdline.mkString(" ")}' exited with code $exitCode")
  }

  private def process(src: TaskKey[Seq[File]], tgt: SettingKey[File])(f: (File, File) => Unit) = Def.task[Seq[File]] {
    val srcFiles = src.value
    val targetDir = tgt.value

    if (srcFiles.isEmpty) Nil
    else synchronized { // some weird threading issues, i'm too lazy to debug them.
      if (targetDir.exists()) IO.delete(targetDir)

      IO.createDirectory(targetDir)
      srcFiles.foreach(f(_, targetDir))
      IO.listFiles(targetDir)
    }
  }

  def generateLexerTask =
    process(sources in generateLexer, target in generateLexer) { (f, t) =>
      val skel = new File("project/skeleton.jflex")
      runJava(classOf[jflex.Main], f.getCanonicalPath, "-d", t.getCanonicalPath, "--skel", skel.getCanonicalPath)
    }

  def generateParserTask =
    process(sources in generateParser, target in generateParser) { (f, t) =>
      runJava(classOf[java_cup.Main], "-destdir", t.getCanonicalPath, "-locations", f.getCanonicalPath)
    }
} 
Example 12
Source File: LagomOpenApiPlugin.scala    From sbt-lagom-descriptor-generator   with Apache License 2.0 5 votes vote down vote up
package com.lightbend.lagom.spec.sbt

import sbt.Keys._
import sbt.plugins.JvmPlugin
import sbt.{ AutoPlugin, File, _ }

object LagomOpenApiPlugin extends AutoPlugin {

  object autoImport {
    val lagomOpenAPIGenerateDescriptor = taskKey[Seq[File]]("Generate Lagom Descriptors from OpenAPI specs.")
  }

  import autoImport._

  override def trigger = noTrigger

  override def requires = JvmPlugin

  override def projectSettings = inConfig(Compile)(openApiSettings) ++ inConfig(Test)(openApiSettings)

  val openApiSettings = Seq(
    sourceDirectory in lagomOpenAPIGenerateDescriptor := sourceDirectory.value / "openapi",
    resourceDirectory in lagomOpenAPIGenerateDescriptor := sourceDirectory.value / "openapi",

    target in lagomOpenAPIGenerateDescriptor :=
      crossTarget.value / "openapi" / Defaults.nameForSrc(configuration.value.name),
    lagomOpenAPIGenerateDescriptor := LagomOpenApiGenerator.lagomOpenAPIGenerateDescriptorTask().value,
    sourceGenerators += Def.task { lagomOpenAPIGenerateDescriptor.value },
    // TODO: review managedSources
    managedSourceDirectories += (target in lagomOpenAPIGenerateDescriptor).value / "java",
    unmanagedResourceDirectories += (resourceDirectory in lagomOpenAPIGenerateDescriptor).value,
    watchSources in Defaults.ConfigGlobal ++= (sources in lagomOpenAPIGenerateDescriptor).value
  ) ++
    inTask(lagomOpenAPIGenerateDescriptor)(
      Seq(
        includeFilter := GlobFilter("*.json") || GlobFilter("*.yaml"),

        managedSourceDirectories := Nil,
        unmanagedSourceDirectories := Seq(sourceDirectory.value),
        sourceDirectories := unmanagedSourceDirectories.value ++ managedSourceDirectories.value,
        unmanagedSources := Defaults.collectFiles(sourceDirectories, includeFilter, excludeFilter).value,
        managedSources := Nil,
        sources := managedSources.value ++ unmanagedSources.value,

        managedResourceDirectories := Nil,
        unmanagedResourceDirectories := Seq(resourceDirectory.value),
        resourceDirectories := unmanagedResourceDirectories.value ++ managedResourceDirectories.value,
        unmanagedResources := Defaults.collectFiles(resourceDirectories, includeFilter, excludeFilter).value,
        managedResources := Nil,
        resources := managedResources.value ++ unmanagedResources.value

      )
    )
} 
Example 13
Source File: Build.scala    From troy   with Apache License 2.0 5 votes vote down vote up
import com.typesafe.sbt.{ GitPlugin, SbtScalariform }
import de.heikoseeberger.sbtheader.HeaderPlugin
import de.heikoseeberger.sbtheader.license.Apache2_0
import sbt._
import sbt.plugins.JvmPlugin
import sbt.Keys._
import scalariform.formatter.preferences.{ AlignSingleLineCaseStatements, DoubleIndentClassDeclaration }
import bintray.BintrayKeys._

object Build extends AutoPlugin {

  override def requires = JvmPlugin && HeaderPlugin && GitPlugin && SbtScalariform

  override def trigger = allRequirements

  def compileSettings = Vector(
    // Core settings
    organization := "io.github.cassandra-scala",
    licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
    scalaVersion := Version.Scala,
    scalaOrganization := "org.typelevel", // FIXME: Remove once literal-types is merged into lightbend Scala
    crossScalaVersions := Vector("2.11.8", "2.12.1"),
    scalacOptions ++= Vector(
      "-encoding", "UTF-8",
      "-target:jvm-1.8",
      "-language:_",
      "-unchecked",
      "-feature",
      "-deprecation",
      "-Xlint",
      "-Xfuture",
      "-Ywarn-dead-code",
      "-Ywarn-unused-import",
      "-Ywarn-unused",
      "-Ywarn-nullary-unit",
      "-Yliteral-types"
    ),
    scalacOptions in (Compile, console) := Seq("-Yliteral-types"),
    unmanagedSourceDirectories.in(Compile) := Vector(scalaSource.in(Compile).value),
    unmanagedSourceDirectories.in(Test) := Vector(scalaSource.in(Test).value)
  )

  def testSettings = Vector(
    parallelExecution in Test := false,
    publishArtifact in Test := false
  )

  def stablePublishSettings = Vector(
    publishArtifact in Test := false,

    pomExtra := (
      <modules>
        <module>cql-ast</module>
        <module>cql-parser</module>
        <module>troy-schema</module>
        <module>troy-driver</module>
        <module>troy</module>
      </modules>
        <scm>
          <url>[email protected]:cassandra-scala/troy.git</url>
          <connection>scm:git:[email protected]:cassandra-scala/troy.git</connection>
        </scm>
        <developers>
          <developer>
            <id>tabdulradi</id>
            <name>Tamer Abdulradi</name>
            <url>http://abdulradi.com</url>
          </developer>
        </developers>),
    licenses := ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.txt")) :: Nil
  )

  def snapshotPublishSettings = Seq() //TODO

  def publishSettings = stablePublishSettings

  def pluginsSettings = Vector(
    // Scalariform settings
    SbtScalariform.autoImport.scalariformPreferences := SbtScalariform.autoImport.scalariformPreferences.value
      .setPreference(AlignSingleLineCaseStatements, true)
      .setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 100)
      .setPreference(DoubleIndentClassDeclaration, true),

    // Git settings
    GitPlugin.autoImport.git.useGitDescribe := true,

    // Header settings
    HeaderPlugin.autoImport.headers := Map("scala" -> Apache2_0("2016", "Tamer AbdulRadi"))
  )

  override def projectSettings =
    Defaults.coreDefaultSettings ++
      compileSettings ++
      testSettings ++
      publishSettings ++
      pluginsSettings
} 
Example 14
Source File: WavesExtensionDockerPlugin.scala    From Waves   with MIT License 5 votes vote down vote up
import WavesDockerKeys._
import sbt.plugins.JvmPlugin
import sbt.{AutoPlugin, Def, Plugins, inTask}
import sbtdocker.DockerPlugin
import sbtdocker.DockerPlugin.autoImport._

object WavesExtensionDockerPlugin extends AutoPlugin {
  override def requires: Plugins = JvmPlugin && DockerPlugin

  override def projectSettings: Seq[Def.Setting[_]] =
    inTask(docker)(
      Seq(
        additionalFiles := Seq.empty,
        exposedPorts := Set.empty,
        baseImage := "com.wavesplatform/node-it:latest",
        dockerfile := {
          new Dockerfile {
            from(baseImage.value)
            add(additionalFiles.value, "/opt/waves/")
            expose(exposedPorts.value.toSeq: _*)
          }
        },
        buildOptions := BuildOptions(removeIntermediateContainers = BuildOptions.Remove.OnSuccess)
      ))
} 
Example 15
Source File: WavesDockerPlugin.scala    From Waves   with MIT License 5 votes vote down vote up
import java.io.File

import WavesDockerKeys._
import sbt.plugins.JvmPlugin
import sbt.{AutoPlugin, Def, Plugins, inTask, taskKey}
import sbtdocker.DockerPlugin
import sbtdocker.DockerPlugin.autoImport._

object WavesDockerPlugin extends AutoPlugin {
  override def requires: Plugins = JvmPlugin && DockerPlugin
  
  override def projectSettings: Seq[Def.Setting[_]] =
    inTask(docker)(
      Seq(
        additionalFiles := Seq.empty,
        exposedPorts := Set.empty,
        baseImage := "anapsix/alpine-java:8_server-jre",
        dockerfile := {
          val yourKitArchive = "YourKit-JavaProfiler-2019.8-docker.zip"
          val bin            = "/opt/waves/start-waves.sh"

          new Dockerfile {
            from(baseImage.value)

            runRaw(s"""mkdir -p /opt/waves && \\
                    |apk update && \\
                    |apk add --no-cache openssl ca-certificates && \\
                    |wget --quiet "https://search.maven.org/remotecontent?filepath=org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar" -O /opt/waves/aspectjweaver.jar && \\
                    |wget --quiet "https://www.yourkit.com/download/docker/$yourKitArchive" -P /tmp/ && \\
                    |unzip /tmp/$yourKitArchive -d /usr/local && \\
                    |rm -f /tmp/$yourKitArchive""".stripMargin)

            add(additionalFiles.value, "/opt/waves/")
            runShell("chmod", "+x", bin)
            entryPoint(bin)
            expose(exposedPorts.value.toSeq: _*)
          }
        },
        buildOptions := BuildOptions(removeIntermediateContainers = BuildOptions.Remove.OnSuccess)
      ))
}

object WavesDockerKeys {
  val additionalFiles = taskKey[Seq[File]]("Additional files to copy to /opt/waves")
  val exposedPorts    = taskKey[Set[Int]]("Exposed ports")
  val baseImage       = taskKey[String]("A base image for this container")
} 
Example 16
Source File: ProtobufScalaPlugin.scala    From jvm-toxcore-c   with GNU General Public License v3.0 5 votes vote down vote up
package im.tox.sbt

import com.github.os72.protocjar.Protoc
import com.trueaccord.scalapb.ScalaPbPlugin._
import sbt.Keys._
import sbt._
import sbt.plugins.{ IvyPlugin, JvmPlugin }

object ProtobufScalaPlugin extends AutoPlugin {

  override def trigger: PluginTrigger = allRequirements
  override def requires: Plugins = IvyPlugin && JvmPlugin

  override def projectSettings: Seq[Setting[_]] = protobufSettings ++ inConfig(protobufConfig)(Seq(
    runProtoc in protobufConfig := { (args: Seq[String]) =>
      Protoc.runProtoc(args.toArray)
    },

    javaSource := (sourceManaged in Compile).value,
    scalaSource := (sourceManaged in Compile).value,

    version := "3.4.0",
    javaConversions := true,
    flatPackage := true,
    grpc := true
  ))

} 
Example 17
Source File: CheckBeamDependencies.scala    From scio   with Apache License 2.0 5 votes vote down vote up
import java.util.concurrent.ConcurrentHashMap
import java.util.function.{Function => JFunction}

import sbt._
import Keys._
import sbt.plugins.JvmPlugin

import scala.sys.process._

object CheckBeamDependencies extends AutoPlugin {
  override def requires: JvmPlugin.type = sbt.plugins.JvmPlugin
  override def trigger: PluginTrigger = allRequirements

  object autoImport {
    val checkBeamDependencies = taskKey[Unit]("check beam dependencies")
  }
  import autoImport._

  private[this] val beamDeps = new ConcurrentHashMap[String, Map[String, Set[String]]]()

  private def resolveBeamDependencies(deps: Seq[(String, String)]): Map[String, Set[String]] =
    deps
      .filter(d => d._1.startsWith("org.apache.beam"))
      .map {
        case (orgName, rev) =>
          beamDeps.computeIfAbsent(
            orgName,
            new JFunction[String, Map[String, Set[String]]] {
              override def apply(key: String): Map[String, Set[String]] = {
                val output = s"coursier resolve $key:$rev" lineStream_!

                output
                  .flatMap { dep =>
                    dep.split(":").toList match {
                      case org :: name :: rev :: _ => Some((s"$org:$name", rev))
                      case _                       => None
                    }
                  }
                  .toList
                  .groupBy(_._1)
                  .mapValues(_.map(_._2).toSet)
              }
            }
          )
      }
      .foldLeft(Map.empty[String, Set[String]])(_ ++ _)

  override lazy val projectSettings = Seq(
    checkBeamDependencies := {
      val deps = libraryDependencies.value.map(m => (s"${m.organization}:${m.name}", m.revision))
      val beamDependencies = resolveBeamDependencies(deps)
      val projectBeamDeps = deps
        .map(dep => (dep, beamDependencies.getOrElse(dep._1, Nil)))
        .collect {
          case ((dep, version), beamVersions) => beamVersions.map(v => (dep, (version, v)))
        }
        .flatten

      streams.value.log.warn {
        (thisProjectRef.value.project :: projectBeamDeps.collect {
          case (org, (v1, v2)) if v1 != v2 =>
            s"* $org:$v1 -> beam: $v2"
        }.toList).mkString("\n")
      }
    }
  )
} 
Example 18
Source File: DexItDockerPlugin.scala    From matcher   with MIT License 5 votes vote down vote up
import java.io.File

import sbt.plugins.JvmPlugin
import sbt.{AutoPlugin, Def, LocalProject, PluginTrigger, Plugins, inTask, taskKey}
import sbtdocker.DockerPlugin
import sbtdocker.DockerPlugin.autoImport._

object DexItDockerPlugin extends AutoPlugin {

  import DexItDockerKeys._

  override def requires: Plugins      = JvmPlugin && DockerPlugin
  override def trigger: PluginTrigger = PluginTrigger.NoTrigger

  override def projectSettings: Seq[Def.Setting[_]] =
    inTask(docker)(
      Seq(
        additionalFiles := Seq.empty,
        exposedPorts := Set(6886),
        baseImage := "com.wavesplatform/waves-dex:latest",
        dockerfile := {
          new Dockerfile {
            from(baseImage.value)
            add(additionalFiles.value, "/opt/waves-dex/")
            expose(exposedPorts.value.toSeq: _*)
          }
        },
        buildOptions := BuildOptions(removeIntermediateContainers = BuildOptions.Remove.OnSuccess)
      )) ++ Seq(
      docker := docker.dependsOn(LocalProject("dex") / docker).value
    )
}

object DexItDockerKeys {
  val additionalFiles = taskKey[Seq[File]]("Additional files to copy to /opt/waves-dex")
  val exposedPorts    = taskKey[Set[Int]]("Exposed ports")
  val baseImage       = taskKey[String]("A base image for this container")
} 
Example 19
Source File: TypelevelScalaOrganization.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.detectscalaorganization

import sbt.plugins.JvmPlugin
import sbt._, Keys._

object TypelevelScalaOrganization extends AutoPlugin {
  override def trigger = allRequirements

  override def requires = JvmPlugin

  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    scalaOrganization in updateSbtClassifiers := {
      (scalaOrganization in Global).value
    },
    scalaOrganization := {
      val unchanged = scalaOrganization.value
      scalaVersion.value match {
        case VersionNumber(_, tags, _) if tags.contains("typelevel") =>
          "org.typelevel"
        case _ =>
          unchanged
      }
    }
  )
} 
Example 20
Source File: PackageUnidoc.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.publishUnidoc

import sbt.{Def, _}
import Keys._
import sbt.Defaults.{packageDocMappings, packageTaskSettings}
import sbt.plugins.JvmPlugin
import sbtunidoc.UnidocKeys


object PackageUnidoc extends AutoPlugin with UnidocKeys {

  override def requires: Plugins = JvmPlugin

  override def trigger: PluginTrigger = allRequirements

  object autoImport {
    val unidocProject = settingKey[Option[ProjectRef]](
      "The project that defines a unidoc task. If this `unidocProject` setting is not None, packageDoc will use files generated from unidoc instead of per project doc")
  }
  import autoImport._

  override def globalSettings: Seq[Def.Setting[_]] = {
    unidocProject := None
  }

  override def projectSettings: Seq[Def.Setting[_]] = {
    inConfig(Compile)(
      packageTaskSettings(
        packageDoc,
        Def.taskDyn {
          unidocProject.value match {
            case None    => packageDocMappings
            case Some(p) => (unidoc in Compile in p).map(_.flatMap(Path.allSubpaths))
          }
        }
      ))
  }

} 
Example 21
Source File: ScalacWarnings.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.scalacOptions

import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin


object ScalacWarnings extends AutoPlugin {

  override def requires = JvmPlugin

  override def trigger = allRequirements

  override def projectSettings = Seq(
    scalacOptions += "-feature",
    scalacOptions in Compile += "-deprecation",
    scalacOptions += "-unchecked",
    scalacOptions ++= {
      import Ordering.Implicits._
      VersionNumber(scalaVersion.value).numbers match {
        case numbers if numbers >= Seq(2L, 13L) =>
          Some("-Xlint:infer-any")
        case numbers if numbers >= Seq(2L, 11L) =>
          Some("-Ywarn-infer-any")
        case _ =>
          None
      }
    }
  )

} 
Example 22
Source File: Optimization.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.scalacOptions

import com.thoughtworks.sbtBestPractice.scalacOptions.ScalacWarnings.allRequirements
import sbt.{Def, _}
import sbt.Keys._
import sbt.plugins.JvmPlugin


object Optimization extends AutoPlugin {

  override def requires: Plugins = JvmPlugin

  override def trigger: PluginTrigger = allRequirements

  object autoImport {
    val optimization = settingKey[Boolean]("Whether to enable scalac flags for optimization")
  }
  import autoImport._

  override def globalSettings: Seq[Def.Setting[_]] = Seq(
    optimization := false
  )

  override def projectSettings = Seq(
    scalacOptions ++= {
      if (optimization.value) {
        import scala.math.Ordering.Implicits._
        val versionNumbers = VersionNumber(scalaVersion.value).numbers
        if (versionNumbers < Seq(2L, 12L)) {
          Seq("-optimize", "-Yinline-warnings")
        } else if (versionNumbers < Seq(2L, 12L, 3L)) {
          Seq("-opt:l:project")
        } else {
          Seq("-opt:l:inline", "-opt-inline-from:<sources>")
        }
      } else {
        Nil
      }
    }
  )

} 
Example 23
Source File: ScaladocFeatures.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.scalacOptions

import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin


object ScaladocFeatures extends AutoPlugin {

  override def requires = JvmPlugin

  override def trigger = allRequirements

  override val projectSettings = Seq(
    scalacOptions in Compile in doc += "-groups",
    scalacOptions in Compile in doc += "-diagrams",
    scalacOptions in Compile in doc += "-implicits",
    scalacOptions in Compile in doc ++= {
      if (scalaBinaryVersion.value == "2.10") {
        Seq()
      } else {
        Seq("-author")
      }
    }
  )
} 
Example 24
Source File: ClasspathCache.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.scalacOptions

import sbt._
import Keys._
import sbt.plugins.JvmPlugin


object ClasspathCache extends AutoPlugin {
  override def trigger = allRequirements

  override def requires = JvmPlugin

  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    scalacOptions ++= {
      import scala.Ordering.Implicits._
      if (VersionNumber(scalaVersion.value).numbers >= Seq(2L, 12L, 5L)) {
        Seq("-Ycache-plugin-class-loader:last-modified", "-Ycache-macro-class-loader:last-modified")
      } else {
        Nil
      }
    }
  )
} 
Example 25
Source File: TravisUnidoc.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.travis

import sbt.plugins.JvmPlugin
import sbt._
import Keys._
import sbtunidoc.{ScalaUnidocPlugin, UnidocKeys}


object TravisUnidoc extends AutoPlugin with UnidocKeys {
  override def requires: Plugins = Travis && JvmPlugin && ScalaUnidocPlugin

  override def trigger: PluginTrigger = allRequirements

  override def projectSettings = Seq(
    scalacOptions in Compile in doc := {
      val originalScalacOptions = (scalacOptions in Compile in doc).value
      Travis.travisRepoSlug.?.value match {
        case Some(slug) =>
          originalScalacOptions.indexOf("-doc-title") match {
            case -1 =>
              originalScalacOptions ++ Seq("-doc-title", slug)
            case i =>
              originalScalacOptions.updated(i + 1, slug)
          }
        case None =>
          originalScalacOptions
      }
    }
  )

} 
Example 26
Source File: Build.scala    From healthchecks   with MIT License 5 votes vote down vote up
import bintray.BintrayPlugin
import bintray.BintrayPlugin.autoImport._
import com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin.autoImport._
import de.heikoseeberger.sbtheader.HeaderPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import sbtrelease.ReleasePlugin.autoImport._
import sbt.Keys._
import sbt.{AutoPlugin, _}
import sbt.plugins.JvmPlugin

object Build extends AutoPlugin {
  override def requires = JvmPlugin && HeaderPlugin && BintrayPlugin

  override def trigger = allRequirements

  override def projectSettings = Vector(
    // Core settings
    organization := "com.github.everpeace",
    organizationName := "Shingo Omura",
    startYear := Some(2017),
    licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
    headerLicense := Some(HeaderLicense.MIT("2017", "Shingo Omura")),
    homepage := Some(url("https://github.com/everpeace/healthchecks")),
    pomIncludeRepository := (_ => false),
    pomExtra := <scm>
      <url>https://github.com/everpeace/healthchecks</url>
      <connection>scm:git:[email protected]:everpeace/healthchecks</connection>
    </scm>
      <developers>
        <developer>
          <id>everpeace</id>
          <name>Shingo Omura</name>
          <url>http://everpeace.github.io/</url>
        </developer>
      </developers>,
    scalaVersion := Version.Scala.head,
    crossScalaVersions := Version.Scala,
    scalacOptions ++= Vector(
      "-unchecked",
      "-deprecation",
      "-language:_",
      "-encoding", "UTF-8",
      "-Ywarn-unused-import",
      "-Ypartial-unification"
    ),

    // Scalafmt setting
    scalafmtOnCompile := true,
    scalafmtTestOnCompile := true,

    // macro compiler plugin
    addCompilerPlugin(
      "org.scalamacros" % "paradise" % Version.paradise cross CrossVersion.full
    ),

    // Bintray settings
    bintrayPackage := "healthchecks",
    bintrayRepository := "maven",

    releaseCrossBuild := true,
    releaseVersionBump := sbtrelease.Version.Bump.Next
  )
} 
Example 27
Source File: KotlinPlugin.scala    From kotlin-plugin   with MIT License 5 votes vote down vote up
package kotlin

import Keys._
import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin


object KotlinPlugin extends AutoPlugin {
  override def trigger = allRequirements
  override def requires = JvmPlugin

  override def projectConfigurations = KotlinInternal :: Nil

  override def globalSettings = (onLoad := onLoad.value andThen { s =>
    Project.runTask(updateCheck in Keys.Kotlin, s).fold(s)(_._1)
  }) :: Nil

  private def kotlinScriptCompilerDeps(kotlinVer: String) = {
    import scala.math.Ordering.Implicits.infixOrderingOps

    if (KotlinVersion(kotlinVer) <= KotlinVersion("1.3.21")) {
      Seq(
        "org.jetbrains.kotlin" % "kotlin-script-runtime" % kotlinVer
      )
    } else {
      Seq(
        "org.jetbrains.kotlin" % "kotlin-scripting-compiler-embeddable" % kotlinVer % KotlinInternal.name,
        "org.jetbrains.kotlin" % "kotlin-scripting-compiler-embeddable" % kotlinVer
      )
    }
  }

  override def projectSettings = Seq(
    libraryDependencies ++= Seq(
      "org.jetbrains.kotlin" % "kotlin-compiler-embeddable" % kotlinVersion.value % KotlinInternal.name
    ) ++ kotlinScriptCompilerDeps(kotlinVersion.value),
    managedClasspath in KotlinInternal := Classpaths.managedJars(KotlinInternal, classpathTypes.value, update.value),
    updateCheck in Kotlin := {
      val log = streams.value.log
      UpdateChecker("pfn", "sbt-plugins", "kotlin-plugin") {
        case Left(t) =>
          log.debug("Failed to load version info: " + t)
        case Right((versions, current)) =>
          log.debug("available versions: " + versions)
          log.debug("current version: " + BuildInfo.version)
          log.debug("latest version: " + current)
          if (versions(BuildInfo.version)) {
            if (BuildInfo.version != current) {
              log.warn(
                s"UPDATE: A newer kotlin-plugin is available:" +
                  s" $current, currently running: ${BuildInfo.version}")
            }
          }
      }
    },
    kotlinVersion := "1.3.50",
    kotlincOptions := Nil,
    kotlincPluginOptions := Nil,
    watchSources     ++= {
      import language.postfixOps
      val kotlinSources = "*.kt" || "*.kts"
      (sourceDirectories in Compile).value.flatMap(_ ** kotlinSources get) ++
        (sourceDirectories in Test).value.flatMap(_ ** kotlinSources get)
    }
  ) ++ inConfig(Compile)(kotlinCompileSettings) ++
    inConfig(Test)(kotlinCompileSettings)

  val autoImport = Keys

  // public to allow kotlin compile in other configs beyond Compile and Test
  val kotlinCompileSettings = List(
    unmanagedSourceDirectories += kotlinSource.value,
    kotlincOptions := kotlincOptions.value,
    kotlincPluginOptions := kotlincPluginOptions.value,
    kotlinCompile := Def.task {
        KotlinCompile.compile(kotlincOptions.value,
          sourceDirectories.value, kotlincPluginOptions.value,
          dependencyClasspath.value, (managedClasspath in KotlinInternal).value,
          classDirectory.value, streams.value)
    }.dependsOn (compileInputs in (Compile,compile)).value,
    compile := (compile dependsOn kotlinCompile).value,
    kotlinSource := sourceDirectory.value / "kotlin",
    definedTests in Test ++= KotlinTest.kotlinTests.value
  )
} 
Example 28
Source File: Common.scala    From play-file-watch   with Apache License 2.0 5 votes vote down vote up
import Dependencies._
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin

object Common extends AutoPlugin {

  override def trigger = noTrigger

  override def requires = JvmPlugin

  val repoName = "play-file-watch"

  val javacParameters = Seq(
    "-source",
    "1.8",
    "-target",
    "1.8",
    "-Xlint:deprecation",
    "-Xlint:unchecked"
  )

  val scalacParameters = Seq(
    "-target:jvm-1.8",
    "-encoding",
    "utf8",
    "-deprecation",
    "-feature",
    "-unchecked",
    "-Xlint",
    "-Ywarn-unused:imports",
    "-Xlint:nullary-unit",
    "-Ywarn-dead-code"
  )

  override def globalSettings =
    Seq(
      organization := "com.lightbend.play",
      organizationName := "Lightbend Inc.",
      organizationHomepage := Some(url("https://www.lightbend.com/")),
      homepage := Some(url(s"https://github.com/playframework/${repoName}")),
      licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")),
      scalaVersion := Scala212,
      crossScalaVersions := ScalaVersions,
      scalacOptions ++= scalacParameters,
      javacOptions ++= javacParameters,
      scmInfo := Some(
        ScmInfo(
          url(s"https://github.com/playframework/${repoName}"),
          s"scm:git:[email protected]:playframework/${repoName}.git"
        )
      ),
      developers += Developer(
        "contributors",
        "Contributors",
        "https://gitter.im/playframework/contributors",
        url("https://github.com/playframework")
      ),
      description := "Play File Watch Library. Watch files in a platform independent way."
    )

} 
Example 29
Source File: Common.scala    From play-json   with Apache License 2.0 5 votes vote down vote up
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin

object Common extends AutoPlugin {
  override def trigger = allRequirements

  override def requires = JvmPlugin

  val repoName = "play-json"

  override def globalSettings =
    Seq(
      organization := "com.typesafe.play",
      organizationName := "Lightbend Inc.",
      organizationHomepage := Some(url("https://www.lightbend.com/")),
      homepage := Some(url(s"https://github.com/playframework/${repoName}")),
      licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")),
      scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-encoding", "utf8"),
      javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:-options"),
      scmInfo := Some(
        ScmInfo(
          url(s"https://github.com/playframework/${repoName}"),
          s"scm:git:[email protected]:playframework/${repoName}.git"
        )
      ),
      developers += Developer(
        "contributors",
        "Contributors",
        "https://gitter.im/playframework/contributors",
        url("https://github.com/playframework")
      ),
      description := "Play JSON"
    )
} 
Example 30
Source File: Common.scala    From constructr-consul   with Apache License 2.0 5 votes vote down vote up
import com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin.autoImport.{ scalafmtOnCompile, scalafmtVersion }
import com.typesafe.sbt.GitPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import de.heikoseeberger.sbtheader._
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin

object Common extends AutoPlugin {

  override def requires = JvmPlugin && HeaderPlugin && GitPlugin

  override def trigger = allRequirements

  override def projectSettings =
    Seq(
      // Core settings
      organization := "com.tecsisa",
      organizationName := "Tecnología, Sistemas y Aplicaciones S.L.",
      organizationHomepage := Some(url("http://www.tecsisa.com/")),
      scmInfo := Some(
        ScmInfo(
          url("https://github.com/Tecsisa/constructr-consul"),
          "[email protected]:Tecsisa/constructr-consul.git")),
      developers += Developer(
        "contributors",
        "Contributors",
        "",
        url("https://github.com/Tecsisa/constructr-consul/graphs/contributors")),
      licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
      homepage := Some(url("https://github.com/Tecsisa/constructr-consul")),
      pomIncludeRepository := (_ => false),
      scalaVersion := crossScalaVersions.value.head,
      crossScalaVersions := Version.ScalaVersions,
      crossVersion := CrossVersion.binary,
      scalacOptions ++= Seq(
        "-encoding",
        "UTF-8",
        "-unchecked",
        "-deprecation",
        "-Xlint",
        "-Yno-adapted-args",
        "-Ywarn-dead-code",
        "-Ywarn-unused-import", // only 2.11
        "-Xfuture" // prevents of future breaking changes
      ),
      javacOptions ++= Seq(
        "-Xlint:unchecked"
      ),
      // Git settings
      GitPlugin.autoImport.git.useGitDescribe := true,
      // Header settings
      headerLicense := Some(
        HeaderLicense
          .ALv2("2016 - 2018", "TECNOLOGIA, SISTEMAS Y APLICACIONES S.L. <http://www.tecsisa.com>")
      ),
      headerMappings := headerMappings.value ++ Map(
        FileType.scala -> CommentStyle.cStyleBlockComment
      ),
      // Scalafmt settings
      scalafmtOnCompile in ThisBuild := true,
      scalafmtVersion in ThisBuild := Version.Scalafmt
    )
} 
Example 31
Source File: Common.scala    From play-table-of-contents   with MIT License 5 votes vote down vote up
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin


object Common extends AutoPlugin {
  override def trigger               = allRequirements
  override def requires: sbt.Plugins = JvmPlugin

  override def projectSettings = Seq(
    organization := "com.lightbend.restapi",
    version := "1.0-SNAPSHOT",
    resolvers += Resolver.typesafeRepo("releases"),
    javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
    scalacOptions ++= Seq(
      "-encoding",
      "UTF-8", // yes, this is 2 args
      "-target:jvm-1.8",
      "-deprecation",
      "-feature",
      "-unchecked",
      "-Xlint",
      "-Yno-adapted-args",
      "-Ywarn-numeric-widen",
      "-Xfatal-warnings"
    ),
    scalacOptions in Test ++= Seq("-Yrangepos"),
    autoAPIMappings := true
  )
} 
Example 32
Source File: WavesExtensionDockerPlugin.scala    From matcher   with MIT License 5 votes vote down vote up
import java.io.File

import sbt.plugins.JvmPlugin
import sbt.{AutoPlugin, Def, PluginTrigger, Plugins, inTask, taskKey, settingKey}
import sbtdocker.DockerPlugin
import sbtdocker.DockerPlugin.autoImport._

// TODO move to waves-integration-it
object WavesExtensionDockerPlugin extends AutoPlugin {

  import WavesExtensionDockerKeys._

  override def requires: Plugins      = JvmPlugin && DockerPlugin
  override def trigger: PluginTrigger = PluginTrigger.NoTrigger

  override def projectSettings: Seq[Def.Setting[_]] =
    inTask(docker)(
      Seq(
        additionalFiles := Seq.empty,
        exposedPorts := Set.empty,
        baseImage := s"wavesplatform/wavesnode:${wavesNodeVersion.value}",
        dockerfile := {
          new Dockerfile {
            from(baseImage.value)
            // see https://github.com/wavesplatform/Waves/blob/master/docker/Dockerfile
            user("root:root")
            add(additionalFiles.value, "/opt/waves/")
            expose(exposedPorts.value.toSeq: _*)
            entryPoint("/opt/waves/start-waves.sh")
          }
        },
        buildOptions := BuildOptions(removeIntermediateContainers = BuildOptions.Remove.OnSuccess)
      ))
}

object WavesExtensionDockerKeys {
  val additionalFiles  = taskKey[Seq[File]]("Additional files to copy to /opt/waves")
  val exposedPorts     = taskKey[Set[Int]]("Exposed ports")
  val baseImage        = taskKey[String]("A base image for this container")
  val wavesNodeVersion = settingKey[String]("A version of Waves Node")
} 
Example 33
Source File: DexDockerPlugin.scala    From matcher   with MIT License 5 votes vote down vote up
import java.io.File

import DexDockerKeys._
import sbt.plugins.JvmPlugin
import sbt.{AutoPlugin, Def, Plugins, inTask, taskKey}
import sbtdocker.DockerPlugin
import sbtdocker.DockerPlugin.autoImport._

object DexDockerPlugin extends AutoPlugin {
  override def requires: Plugins = JvmPlugin && DockerPlugin

  override def projectSettings: Seq[Def.Setting[_]] =
    inTask(docker)(
      Seq(
        imageNames := Seq(ImageName("com.wavesplatform/waves-dex:latest")),
        additionalFiles := Seq.empty,
        exposedPorts := Set(
          6886, // REST API
          10001 // Profiler
        ),
        baseImage := "anapsix/alpine-java:8_server-jre",
        dockerfile := new Dockerfile {
          from(baseImage.value)
          val yourKitArchive = "YourKit-JavaProfiler-2019.8-docker.zip"
          val bin            = "/opt/waves-dex/start.sh"

          // See https://www.yourkit.com/docs/java/help/docker.jsp
          runRaw(s"""mkdir -p /opt/waves-dex && \\
                    |apk update && \\
                    |apk add --no-cache openssl ca-certificates && \\
                    |wget --quiet "https://search.maven.org/remotecontent?filepath=org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar" -O /opt/waves-dex/aspectjweaver.jar && \\
                    |wget --quiet "https://www.yourkit.com/download/docker/$yourKitArchive" -P /tmp/ && \\
                    |unzip /tmp/$yourKitArchive -d /usr/local && \\
                    |rm -f /tmp/$yourKitArchive""".stripMargin)

          add(additionalFiles.value, "/opt/waves-dex/")
          runShell("chmod", "+x", bin)
          entryPoint(bin)
          expose(exposedPorts.value.toSeq: _*)
        },
        buildOptions := BuildOptions(removeIntermediateContainers = BuildOptions.Remove.OnSuccess)
      ))
}

object DexDockerKeys {
  val additionalFiles = taskKey[Seq[File]]("Additional files to copy to /opt/waves-dex/")
  val exposedPorts    = taskKey[Set[Int]]("Exposed ports")
  val baseImage       = taskKey[String]("A base image for this container")
}