如何从Play中删除所有默认解析器!应用?

时间:2013-07-05 14:04:07

标签: playframework sbt typesafe-stack maven-central typesafe

背景:我们公司有几个Play!应用程序,它们的测试在我们的内部CI中运行。每个Play应用程序都通过http检索各种公共存储库的依赖关系。这不是理想的(它绕过我们的内部Nexus存储库)但可以忍受。现在我们正在添加额外的CI容量,并且不希望允许新计算机能够访问防火墙外部。

在示例Play应用中,project/Build.scala中的以下配置不足以阻止构建转到repo.typesafe.comrepo1.maven.org

sbtResolver := "Typesafe (proxy)" at "http://repo-1/nexus/content/repositories/typesafe-releases/"

resolvers := Seq(
  "Maven Central (proxy)" at "http://repo-1/nexus/content/repositories/central/",
  "Typesafe (proxy)" at "http://repo-1/nexus/content/repositories/typesafe-releases/",
  // some more internal Nexus repositories
)

externalResolvers := Seq.empty

repo-1是我们的内部Nexus主机,它代理Maven Central,Typesafe和其他存储库)

当我从Maven Central(例如Guava)或者从Typesafe的存储库(例如Play mailer插件)中删除一些依赖项,并运行play compile时,我从输出中看到依赖项仍然是从repo.typesafe.comrepo1.maven.org

[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play-plugins-mailer_2.9.1/2.0.2/play-plugins-mailer_2.9.1-2.0.2.jar ...
[info]  [SUCCESSFUL ] com.typesafe#play-plugins-mailer_2.9.1;2.0.2!play-plugins-mailer_2.9.1.jar (981ms)
[info] downloading http://repo1.maven.org/maven2/com/google/guava/guava/12.0/guava-12.0.jar ...
[info]  [SUCCESSFUL ] com.google.guava#guava;12.0!guava.jar (1422ms)

为了解决这个问题,我们还提供了所有内容的稍微旧版本:Scala 2.9.1,Play 2.0.1,sbt 0.11.3。


如何强制Play应用程序专门从内部存储库中检索依赖项?

2 个答案:

答案 0 :(得分:5)

原来答案是使用正确的sbt语法。

问题中列出的代码是生成构建的配置,但不会将其分配到任何位置。我相信:=替换了resolvers密钥的全局配置,但事实并非如此。

将以下内容放入project/Build.scala迫使Play应用程序解析内部Nexus的依赖关系:

val nexusResolvers = resolvers := Seq(
  "Maven Central (proxy)" at "http://repo-1/nexus/content/repositories/central/",
  "Typesafe (proxy)" at "http://repo-1/nexus/content/repositories/typesafe-releases/",
  // some more internal Nexus repositories
)

注意将resolvers :=的结果分配给新的val,然后将其添加到同一文件中的项目设置中:

val main = PlayProject(...)
  .settings(nexusResolvers: _*)

另外,摆脱配置的sbtResolverexternalResolvers部分,这些部分没有效果。

答案 1 :(得分:3)

编辑或创建/home/YOUR_HOME/.sbt/repositories 添加以下内容:

[repositories] local my-maven-proxy-releases: http://nexus_domain_or_ip:8081/nexus/content/groups/public/

运行播放时

添加此参数:  -Dsbt.override.build.repos =真

例如:activator run -Dsbt.override.build.repos = true

这可以防止加载项目配置中定义的存储库。

有关详细信息,请参阅this