1

我在项目目录中有“Common.scala”:

import sbt.Keys._
import sbt._

import bintray.BintrayKeys._

object Common {

  val commonSettings = Seq(
    organization := "com.github.kondaurovdev",
    scalaVersion := "2.11.8",
    scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"),
    publishLocal := (),
    parallelExecution := false
  )

  val doNotPublishSettings = Seq(
    publish := {},
    publishLocal := {}
  )

  def getPublishSettings(_version: String) = {

    if (_version.endsWith("-SNAPSHOT")) {
      {
        println("is snapshot!")
        Seq(
          publishTo := Some("Artifactory Realm" at "http://oss.jfrog.org/artifactory/oss-snapshot-local"),
          bintrayReleaseOnPublish := false,
          credentials := List(Path.userHome / ".bintray" / ".artifactory").filter(_.exists).map(Credentials(_))
        )
      }
    } else {
      {
        println("is release")
        Seq(
          bintrayOmitLicense := true,
          bintrayRepository := "maven",
          publishArtifact in Test := false,
          pomExtra :=
            <developers>
              <developer>
                <id>kondaurovdev</id>
                <name>Alexander Kondaurov</name>
                <email>kondaurov.dev@gmail.com</email>
              </developer>
            </developers>
        )
      }
    } ++ Seq(
      licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
    )
  }

  def myProject(name: String, _version: String = "0.1.1-SNAPSHOT", deps: Seq[ModuleID] = Seq(), settings: Seq[Def.SettingsDefinition] = Seq(), path: Option[String] = None): Project = {
    Project(name, file(path.getOrElse(name)))
      .settings(
        commonSettings ++
        getPublishSettings(_version)
      )
      .settings(
        libraryDependencies ++= deps,
        version := _version
      )
      .settings(
        settings: _*
      )
  }

}

因此,我在“build.sbt”中有项目:

lazy val snippets: Project = {

  Common.myProject("snippets", deps = Seq(
    Deps.specs2,
    Deps.Log.slf4j
  ))

}

当我尝试“snippets/publish”时,我得到这个错误:

> snippets/publish
[info] Wrote /Users/alexanderkondaurov/Projects/kondaurov/scala/snippets/target/scala-2.11/snippets_2.11-0.1-SNAPSHOT.pom
[info] :: delivering :: com.github.kondaurovdev#snippets_2.11;0.1-SNAPSHOT :: 0.1-SNAPSHOT :: integration :: Sat Jan 21 14:42:01 MSK 2017
[info]  delivering ivy file to /Users/alexanderkondaurov/Projects/kondaurov/scala/snippets/target/scala-2.11/ivy-0.1-SNAPSHOT.xml
[error] Unable to find credentials for [Artifactory Realm @ oss.jfrog.org].
[trace] Stack trace suppressed: run last snippets/*:bintrayEnsureLicenses for the full output.
[trace] Stack trace suppressed: run last snippets/*:publish for the full output.
[error] (snippets/*:bintrayEnsureLicenses) you must define at least one license for this project. Please choose one or more of
[error]  AFL-3.0, AGPL-V3, APL-1.0, APSL-2.0, Apache-1.0, Apache-1.1, Apache-2.0, Artistic-License-2.0, Attribution, BSD, BSD New, BSD Simplified, BSL-1.0, Bouncy-Castle, CA-TOSL-1.1, CDDL-1.0, CPAL-1.0, CPL-1.0, CPOL-1.02, CUAOFFICE-1.0, Codehaus, Day, Day-Addendum, ECL2, EUDATAGRID, EUPL-1.1, Eclipse-1.0, Eiffel-2.0, Entessa-1.0, Fair, Frameworx-1.0, GPL-2.0, GPL-2.0+CE, GPL-3.0, HSQLDB, Historical, IBMPL-1.0, IPAFont-1.0, ISC, IU-Extreme-1.1.1, JA-SIG, JSON, JTidy, LGPL-2.1, LGPL-3.0, Lucent-1.02, MIT, MPL-2.0, MS-PL, MS-RL, MirOS, Motosoto-0.9.1, Mozilla-1.1, Multics, NASA-1.3, NAUMEN, NOSL-3.0, NTP, Nethack, Nokia-1.0a, OCLC-2.0, OSL-3.0, Openfont-1.1, Opengroup, PHP-3.0, PostgreSQL, Public Domain, Public Domain - SUN, PythonPL, PythonSoftFoundation, QTPL-1.0, RPL-1.5, Real-1.0, RicohPL, SUNPublic-1.0, SimPL-2.0, Sleepycat, Sybase-1.0, TMate, Unlicense, UoI-NCSA, VovidaPL-1.0, W3C, WTFPL, Xnet, ZLIB, ZPL-2.0, wxWindows
[error] (snippets/*:publish) java.io.IOException: Access to URL http://oss.jfrog.org/artifactory/oss-snapshot-local/com/github/kondaurovdev/snippets_2.11/0.1-SNAPSHOT/snippets_2.11-0.1-SNAPSHOT.pom was refused by the server: Unauthorized
[error] Total time: 2 s, completed Jan 21, 2017 2:42:03 PM
> 

我不明白为什么它抱怨许可证,我已经包含了 MIT 许可证。我关注了这篇文章:http ://szimano.org/automatic-deployments-to-jfrog-oss-and-bintrayjcentermaven-central-通过-travis-ci-来自-sbt/

添加:

我通过在“credentials += ...”之后移动“licenses += ("MIT", url(" http://opensource.org/licenses/MIT "))”解决了这个许可证问题

现在它看起来像:

Seq(
  publishTo := Some("Artifactory Realm" at "https://oss.jfrog.org/artifactory/oss-snapshot-local"),
  bintrayReleaseOnPublish := false,
  credentials := List(Path.userHome / ".bintray" / ".artifactory").filter(_.exists()).map(Credentials(_)),
  licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
)

这很奇怪..凭证文件看起来像:

realm = Artifactory Realm
host = oss.jfrog.org
user = *********
password = ***********

而且我知道,为了上传快照包,必须通过请求支持服务来获得批准。他们将为您的包裹创建文件夹。这个程序需要为每个包裹完成,你在开玩笑吗?

我在这里有一个帐户“ https://oss.sonatype.org/ ”。我有命名空间,可以根据需要上传尽可能多的包,我期望在 OJO 中具有相同的行为。每次我有新包裹时,我都不会向支持服务提出批准请求

4

1 回答 1

1

设置凭据~/.sbt/是前进的方向。凭证可以在 build.sbt 中,但是用户名、密码以及存储库服务器的 IP 地址以明文形式保留。

要通过配置文件设置凭据,您可以使用:

credentials += Credentials(Path.userHome / ".sbt" / ".credentials")

这会在一个名为的文件中获取凭据,该文件.credentials存储在我的~/.sbt/目录中。

要在 Credentials obj 中设置凭据,您可以使用以下内容:

credentials += Credentials("Artifactory Realm", "http://<ip>:<port>/artifactory/<repo-key>", "<username>", "<password>")

确保publishTo已使用相关解析器进行设置也很重要。一个例子是:

publishTo := Some("Artifactory Realm" at "http://<ip>:<port>/artifactory/<repo-key>

配置代理。可以将以下内容添加到名为repositoriesstored in的文件中~/.sbt/。示例配置可能如下所示:

[repositories]
local
my-ivy-proxy-releases: http://<host>:<port>/artifactory/<repo-key>/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://<host>:<port>/artifactory/<repo-key>/
于 2017-01-25T17:54:19.300 回答