2

我正在创建一个需要另一个 scalaj 库的 sbt 插件。我在本地发布库并尝试使用另一个项目运行/测试它。

但是,当我用另一个项目测试插件时,它显示java.lang.NoClassDefFoundError: scalaj/http/Http$

这是我的代码..

插件构建.sbt

name := "hello-sbt-plugin"
version := "1.0"
scalaVersion := "2.10.4"
scalacOptions ++= Seq("-deprecation", "-feature")
organization := "com.abc.dev"
sbtPlugin := true
publishMavenStyle := false
libraryDependencies += "org.scalaj" %% "scalaj-http" % "0.3.16"
initialCommands in console := "import com.typesafe.sbt.rss._"

插件项目/plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.5.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "0.8.1")

libraryDependencies <+= (sbtVersion) { sv =>
  "org.scala-sbt" % "scripted-plugin" % sv
}

// Scripted plugin needs to declare this as a dependency
libraryDependencies += "jline" % "jline" % "2.11"
libraryDependencies += "org.scalaj" %% "scalaj-http" % "0.3.16"

插件plugin.scala

package com.abc.dev

import sbt._
import Keys._
import plugins._
import sbt.plugins.JvmPlugin
import scalaj.http.Http
import scalaj.http.HttpOptions

object HelloPlugin extends AutoPlugin {

  object autoImport {
    val rssList = settingKey[Map[String, String]]("The list of RSS urls to update.")
    val gatlingses = inputKey[Unit]("Prints RSS")
  }

  import autoImport._
  override def trigger: PluginTrigger = allRequirements
  override def requires = JvmPlugin

  override def projectSettings: Seq[Setting[_]] = Seq(
    gatlingsesSetting
  )

  def gatlingsesSetting: Setting[_] = gatlingses := {
  /*Things*/
  }

}

下面是测试项目的代码。

构建.sbt

name := "sbt-tester"

version := "1.0"
scalaVersion := "2.12.1"

lazy val myProject = (project in file(".")).enablePlugins(HelloPlugin)

libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.5.3"
libraryDependencies +=  "org.scalaj" %% "scalaj-http" % "2.3.0"

rssList := Map(
  "key" -> "value",
)

项目/插件.sbt

addSbtPlugin("com.abc.dev" % "hello-sbt-plugin" % "1.0")
4

0 回答 0