我使用IvyDE Eclipse插件来解析我的项目(让它称之为A)依赖项。其中一个依赖项是我使用sbt构建的另一个项目(称为B)。构建的最后一部分是调用sbt的publishLocal任务,将B项目的人工制品发布到本地Ivy存储库。
到目前为止,一切正常。但是,当我尝试解决项目A依赖项时,IvyDE会生成一条错误消息,指出它无法解析" doc"和" src"罐子。我可以强制它最终工作,因为它没有解决包含实际代码的主jar。不过,我觉得有点烦人。
在花了相当多的时间寻找解决方案之后,我提出了以下的sbt代码来改变我的项目B配置:
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)
}
}
}
&#13;