2

IvyDE Eclipse プラグインを使用して、プロジェクト (A と呼びましょう) の依存関係を解決しています。これらの依存関係の 1 つは、sbt を使用してビルドする別のプロジェクト (B と呼びます) です。ビルドの最後の部分は、sbt の publishLocal タスクを呼び出して、B プロジェクトのアーティファクトをローカルの Ivy リポジトリに公開することです。

この時点まではすべて正常に機能します。しかし、プロジェクト A の依存関係を解決しようとすると、IvyDE は "doc" および "src" jar の解決に失敗したというエラー メッセージを生成します。実際のコードを含むメイン jar の解決に失敗しないため、最終的に強制的に動作させることができます。それでも、私はそれがやや面倒だと思います。

解決策を探すのにかなりの時間を費やした後、

import sbt.Build
import sbt.Project
import java.io.File
import sbt.PathExtra
import sbt.SettingKey
import sbt.Artifact
import sbt.Keys.{ artifact, artifactName, artifactPath, packageSrc, packageDoc, crossTarget, projectID, scalaVersion, scalaBinaryVersion, moduleName }
import sbt.ScalaVersion
import sbt.Configurations.{ Compile }
import sbt.Configurations

/**
 * The objective here is to make the artefacts published to the local repository by the publishLocal task
 * compatible with the local resolver used by IvyDE.
 * This is achieved by dropping the classifiers from the "doc" and "source" artefacts, and by adding
 * an extra level directory to their paths to avoid clashing with the "jar" main artefact.
 */
object SbtIvyFix extends Build with PathExtra {
  lazy override val projects = Seq(root)
  lazy val root: Project = Project("xlstocsv", new File(".")) settings (
    artifact in (Compile, packageSrc) := {
      (artifact in (Compile, packageSrc)).value.copy(classifier = None)
    },
    artifact in (Compile, packageDoc) := {
      (artifact in (Compile, packageDoc)).value.copy(classifier = None)
    },
    artifactPath in (Compile, packageSrc) <<= myArtifactPathSetting(artifact in (Compile, packageSrc)),
    artifactPath in (Compile, packageDoc) <<= myArtifactPathSetting(artifact in (Compile, packageDoc)))

  // Lifted from the Sbt source artifactPathSetting() function in Defaults.scala
  def myArtifactPathSetting(art: SettingKey[Artifact]) = (crossTarget, projectID, art, scalaVersion in artifactName, scalaBinaryVersion in artifactName, artifactName) {
    (t, module, a, sv, sbv, toString) =>
      {
        t / a.`type` / toString(ScalaVersion(sv, sbv), module, a)
      }
  }
}


これは非常にうまく機能しますが、やややりすぎのように感じます。誰かが同じ結果を達成するためのより簡単な方法を提案できますか?

4

0 に答える 0