加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 如果在SBT中使用SNAPSHOT依赖项,是否可以拒绝发布?

发布时间:2020-12-16 18:21:16 所属栏目:安全 来源:网络整理
导读:我一直不小心发布我的内部项目仍然引用内部SNAPSHOT,但如果你依赖任何SNAPSHOT依赖项,如果有一个SBT插件无法发布将非常有用.是否有人知道SBT中有这样的插件或功能? 解决方法 这是你如何编写这样的插件. 产量 publish[info] :: delivering :: com.example#b_
我一直不小心发布我的内部项目仍然引用内部SNAPSHOT,但如果你依赖任何SNAPSHOT依赖项,如果有一个SBT插件无法发布将非常有用.是否有人知道SBT中有这样的插件或功能?

解决方法

这是你如何编写这样的插件.

产量

> publish
[info] :: delivering :: com.example#b_2.10;0.1.0 :: 0.1.0 :: release :: Fri Jan 13 15:50:53 EST 2017
[info]  delivering ivy file to /xxx/b/target/scala-2.10/ivy-0.1.0.xml
[info] Wrote /xxx/b/target/scala-2.10/b_2.10-0.1.0.pom
[info] Wrote /xxx/a/target/scala-2.10/a_2.10-0.1.0.pom
[info] :: delivering :: com.example#a_2.10;0.1.0 :: 0.1.0 :: release :: Fri Jan 13 15:50:53 EST 2017
[info]  delivering ivy file to /xxx/a/target/scala-2.10/ivy-0.1.0.xml
[trace] Stack trace suppressed: run last b/*:publishConfiguration for the full output.
[trace] Stack trace suppressed: run last a/*:publishConfiguration for the full output.
[error] (b/*:publishConfiguration) SNAPSHOT found in classpath:
[error] com.eed3si9n:treehugger_2.10:0.2.4-SNAPSHOT:compile->default;compile->compile;compile->runtime;compile->default(compile);compile->master
[error] (a/*:publishConfiguration) SNAPSHOT found in classpath:
[error] com.eed3si9n:treehugger_2.10:0.2.4-SNAPSHOT:compile->default;compile->compile;compile->runtime;compile->default(compile);compile->master
[error] com.example:c_2.10:0.1.0-SNAPSHOT:compile->compile;compile->default(compile)
[error] io.netty:netty-all:4.1.8.Final-SNAPSHOT:compile->default;compile->compile;compile->runtime;compile->default(compile);compile->master
[error] Total time: 0 s,completed Jan 13,2017 3:50:53 PM

项目/ build.properties

sbt.version = 0.13.13

项目/ DepsVerifyPlugin.scala

import sbt._
import Keys._

object DepsVerifyPlugin extends sbt.AutoPlugin {
  override def requires = plugins.JvmPlugin
  override def trigger = allRequirements
  override def projectSettings = Seq(
    publishConfiguration := {
      val old = publishConfiguration.value
      val ur = update.value
      ur.configuration("compile") foreach { compileReport =>
        val allModules = compileReport.allModules
        val snapshotDeps = allModules filter { _.revision contains "SNAPSHOT" }
        if (snapshotDeps.nonEmpty) {
          sys.error(
            "SNAPSHOT found in classpath:n" +
            snapshotDeps.mkString("n")
          )
        }
      }
      old
    }
    )
}

build.sbt

val commonSettings: Seq[Setting[_]] = Seq(
    organization in ThisBuild := "com.example",scalaVersion in ThisBuild := "2.10.6",version      in ThisBuild := "0.1.0",resolvers += Resolver.sonatypeRepo("public"),publishTo := Some(Resolver.file("file",new File(Path.userHome.absolutePath+"/test-repo")))
  )

val netty = "io.netty" % "netty-all" % "4.1.8.Final-SNAPSHOT"
val treehugger = "com.eed3si9n" %% "treehugger" % "0.2.4-SNAPSHOT"

lazy val root = (project in file("."))
  .aggregate(a,b,c)
  .settings(
    commonSettings,name := "Hello",publish := ()
  )

lazy val a = (project in file("a"))
  .dependsOn(b,libraryDependencies += netty
  )

lazy val b = (project in file("b"))
  .settings(
    commonSettings,libraryDependencies += treehugger
  )

lazy val c = (project in file("c"))
  .settings(
    commonSettings,version := "0.1.0-SNAPSHOT",publish := ()
  )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读