Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create sbt plugin for avoid publish each scala versions #117

Closed
xuwei-k opened this issue Sep 18, 2019 · 1 comment
Closed

create sbt plugin for avoid publish each scala versions #117

xuwei-k opened this issue Sep 18, 2019 · 1 comment

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Sep 18, 2019

WDYT? 👀

package kind_projector_sbt_plugin

import sbt._
import Keys._
import sbt.io.Using

object KindProjectorSbtPlugin extends AutoPlugin {

  override def requires: Plugins = sbt.plugins.JvmPlugin
  override def trigger = allRequirements

  object autoImport {
    val kindProjectorVersion = settingKey[String]("")
    val kindProjectorSourceURL = settingKey[String]("")
  }

  import autoImport._

  override def extraProjects: Seq[Project] = Seq(extraProject)

  lazy val extraProject: Project =
    Project("kind-projector", file(".kind-projector"))
      .settings(
        // disable publish tasks
        publishArtifact := false,
        publish := {},
        publishLocal := {},
        skip in publish := true,
        // disable sbt-pgp publish tasks as well
        // https://github.com/sbt/sbt-pgp/blob/v1.1.1/pgp-plugin/src/main/scala/com/typesafe/sbt/pgp/PgpKeys.scala#L41-L42
        TaskKey[Unit]("publishSigned") := {},
        TaskKey[Unit]("publishLocalSigned") := {},
        libraryDependencies += scalaOrganization.value % "scala-compiler" % scalaVersion.value,
        kindProjectorVersion := "0.10.3",
        kindProjectorSourceURL := {
          s"https://repo1.maven.org/maven2/org/typelevel/kind-projector_2.13/${kindProjectorVersion.value}/kind-projector_2.13-${kindProjectorVersion.value}-sources.jar"
        },
        sourceGenerators in Compile += task {
          val dir = (sourceManaged in Compile).value
          // TODO cache source jar?
          Using.urlInputStream(url(kindProjectorSourceURL.value)) { stream =>
            IO.unzipStream(stream, dir, _.endsWith(".scala"))
          }
          (dir ** "*.scala").get
        },
        resourceGenerators in Compile += task {
          val dir = (resourceManaged in Compile).value
          Using.urlInputStream(url(kindProjectorSourceURL.value)) { stream =>
            IO.unzipStream(stream, dir, _.endsWith(".xml"))
          }
          (dir ** "*.xml").get
        }
      )
      .disablePlugins(KindProjectorSbtPlugin) 


  override def projectSettings: Seq[Def.Setting[_]] = Def.settings(
    scalacOptions ++= {
      val jar = (Keys.`package` in (extraProject, Compile)).value
      val addPlugin = "-Xplugin:" + jar.getAbsolutePath
      // add plugin timestamp to compiler options to trigger recompile of
      // main after editing the plugin. (Otherwise a 'clean' is needed.)
      val dummy = "-Jdummy=" + jar.lastModified
      Seq(addPlugin, dummy)
    }
  )
}
@lrytz
Copy link

lrytz commented Sep 19, 2019

A downside is that this only supports sbt. I'd prefer publishing fully cross-versioned builds to maven. I've started using https://github.com/olafurpg/sbt-ci-release lately and it makes the process quite painless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants