SBT解决方案因Ivy额外属性而失败

时间:2014-07-01 08:37:13

标签: sbt

我正试图在SBT中使用Ivy额外属性。我有两个模块:foo-model和foo-api。对于他们两个,我将其添加到build.sbt

projectID <<= projectID { id =>
   id extra("branch" -> "master-api-model-separation")
}

Foo模型正在发布到Artifactory(使用sbt发布)。已发布的POM文件如下所示:

<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.foo</groupId>
    <artifactId>foo-model</artifactId>
    <packaging>jar</packaging>
    <description>foo-model</description>
    <version>1.0</version>
    <name>foo-model</name>
    <organization>
        <name>com.foo</name>
    </organization>
    <properties>
        <branch>master-api-model-separation</branch>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.10.3</version>
        </dependency>
        ...

然后我需要foo-api来使用foo-model,所以我把它添加到它的build.sbt:

def appDependencies = Seq(
    "com.foo"%"foo-model"%"1.0" extra( "branch" -> "master-api-model-separation" ) changing(),
    ...

但是,当我尝试运行SBT(更新或打包)时,我得到了这个:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.foo#foo-model;1.0: java.text.ParseException: inconsistent module descriptor file found in 'http://xdctest-app-01:8081/artifactory/foo-master/com/foo/foo-model/1.0/foo-model-1.0.pom': bad branch found in http://xdctest-app-01:808/artifactory/foo-master/com/foo/foo-model/1.0/foo-model-1.0.pom: expected='master-api-model-separation' found='null';
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]          com.foo:foo-model:1.0 (branch=master-api-model-separation)
[warn] 

还有一个例外和错误。我试过SBT 0.13.0和0.13.1。

我没有设法获得更多有用的调试输出。我只从最后一个命令得到这个:

[debug]                 tried http://xdctest-app-01:8081/artifactory/foo-master/com/foo/foo-model/1.0/foo-model-1.0.jar
[debug] com.foo#foo-model;1.0 is changing, but has not changed: will trust cached artifacts if any
[debug] Deleting additional old artifacts from cache for changed module com.foo#foo-model;1.0:
[debug]         
[error]         foo-master: bad branch found in http://xdctest-app-01:8081/artifactory/foo-master/com/foo/foo-model/1.0/foo-model-1.0.pom: expected='master-api-model-separation' found='null'
[debug] problem occurred while resolving dependency: com.foo#foo-model;1.0 {compile=[default(compile)]} with foo-master: java.text.ParseException: inconsistent module descriptor file found in 'http://xdctest-app-01:8081/artifactory/foo-master/com/foo/foo-model/1.0/foo-model-1.0.pom': bad branch found in http://xdctest-app-01:8081/artifactory/foo-master/com/foo/foo-model/1.0/foo-model-1.0.pom: expected='master-api-model-separation' found='null';
[debug]         at org.apache.ivy.plugins.resolver.BasicResolver.checkDescriptorConsistency(BasicResolver.java:640)
[debug]         at org.apache.ivy.plugins.resolver.BasicResolver.getDependency(BasicResolver.java:284)
[debug]         at org.apache.ivy.plugins.resolver.IBiblioResolver.getDependency(IBiblioResolver.java:503)
[debug]         at sbt.ConvertResolver$PluginCapableResolver$1.sbt$ConvertResolver$DescriptorRequired$$super$getDependency(ConvertResolver.scala:28)
...

上述URL中的POM文件确实存在,其内容在上面引用,即。它具有值为master-api-model-separation的分支属性。

我做错了什么?

1 个答案:

答案 0 :(得分:4)

Ivy extra属性可能需要Ivy存储库才能使其正常工作,如果您使用Artifactory,这应该可以使用。 sbt在内部使用额外的属性来编码Maven存储库上的Scala版本,但我不知道这些位是否暴露。

这是我用作测试的内容。

build.sbt

lazy val root = (project in file(".")).
  settings(
    bintrayReleaseOnPublish in ThisBuild := false
  )

val customPattern = "[organisation]/[module]/" +
  "(scala_[scalaVersion]/)(sbt_[sbtVersion]/)(branch_[branch_name]/)" +
  "[revision]/[type]s/[artifact](-[classifier]).[ext]"

lazy val libExtra = (project in file("libExtra")).
  settings(
    version := "0.1",
    scalaVersion := "2.11.7",
    organization := "com.example",
    name := "somelibrary",
    projectID := {
      val previous = projectID.value
      previous.extra("branch_name" -> "master-api-model-separation")
    },
    licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
    bintrayVcsUrl := Some("git@github.com:you/your-repo.git"),
    bintrayOrganization := None,
    bintrayRepository := "test-test-test",
    publishMavenStyle := false,
    checksums in publish := Nil,
    publishTo := {
      Some(URLRepository("test-bintray-ivy", Patterns(
        s"https://api.bintray.com/content/you/${bintrayRepository.value}/" +
        customPattern +
        s";bt_package={normalizedName.value};bt_version={version.value}")))
    }
  )

lazy val app = (project in file("app")).
  settings(
    scalaVersion := "2.11.7",
    organization := "foo",
    libraryDependencies += "com.example" %% "somelibrary" % "0.1" extra("branch_name" -> "master-api-model-separation"),
    resolvers += Resolver.url("test-bintray-ivy", url("https://dl.bintray.com/you/test-test-test/"))(Patterns(
      customPattern)),
    fullResolvers := fullResolvers.value.filterNot(_.name == "inter-project")
  )

项目/ build.properties

sbt.version=0.13.8

项目/ bintray.sbt

addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")

libExtra / SRC /主/阶/东西

object Something

一半的设置基本上设置为发布到虚拟Bintray存储库进行测试。以下是一些注意事项:

  • 名称branch已被采用,因此我认为您无法使用它。我是sugin branch_name
  • publishTo包含一个自定义工件模式,其中包含嵌入在URL中的额外属性。

使用app我能够从Bintray解析JAR:

app> compile
[info] Updating {file:/Users/xxx/extra-attribute-test/}app...
[info] Resolving jline#jline;2.12.1 ...
[info] downloading https://dl.bintray.com/eed3si9n/test-test-test/com/example/somelibrary_2.11/branch_master-api-model-separation/0.1/jars/somelibrary_2.11.jar ...

未来的改进:这是我尝试使用Maven回购尝试来做到这一点 - https://gist.github.com/eed3si9n/a6de413b1ced84649ae0