简体   繁体   English

播放2.0和SNAPSHOT依赖项

[英]Play 2.0 and SNAPSHOT dependencies

I'm setting up my very first play app in a mixed build environment. 我正在混合构建环境中设置我的第一个播放应用程序。 My company uses maven for everything (so far) and I'm trying to get my play app to interact nicely with the rest of my artifacts. 我的公司使用maven来处理所有事情(到目前为止),我正在努力让我的播放应用程序与我的其他工件很好地交互。

Is there any way to get ivy/sbt/play to deal with SNAPSHOTs in a similar way to maven - namely, either update them from the remote repository always (for example, on a build worker) or use the local .m2 repository until the dependency 'expires' and then refresh it from the server. 有没有办法让ivy / sbt / play以类似于maven的方式处理SNAPSHOTs - 即,始终从远程存储库更新它们(例如,在构建工作者上)或使用本地.m2存储库直到依赖'过期'然后从服务器刷新它。

I have declared a SNAPSHOT dependency in my Build.scala for an artifact, and I'd like local updates to this dependency to be visible to my play project. 我在Build.scala中为一个工件声明了一个SNAPSHOT依赖项,我希望这个依赖项的本地更新对我的play项目可见。 On the maven side, I do the following 在maven方面,我做了以下几点

mvn clean install

which (of course) builds and installs my external artifact to my local maven repository (at ~/.m2/repository). 其中(当然)构建并将我的外部工件安装到我的本地maven存储库(在〜/ .m2 / repository)。 I'd like these changes to be immediately visible to my play project, but I can't figure out how to tell sbt/play to not cache SNAPSHOTs. 我希望我的播放项目能立即看到这些更改,但我无法弄清楚如何告诉sbt / play不缓存SNAPSHOT。 No matter what I do, this dependency is never refreshed in play - I have to go into the actual play ivy cache and delete the dependency by hand for any changes to be picked up. 无论我做什么,这种依赖关系永远不会在游戏中刷新 - 我必须进入实际的游戏常春藤缓存并手动删除依赖关系以获取任何更改。 Ideally, I'd like sbt/ivy to just resolve the path to my local maven repo and not cache it internally. 理想情况下,我希望sbt / ivy只是解析我本地maven仓库的路径,而不是在内部缓存它。 I've got the following in my Build.scala 我的Build.scala中有以下内容

val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
    resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",
    testOptions in Test := Nil
)

When I run a build in play, it properly uses this repo, but then caches the results in the ivy cache. 当我在游戏中运行构建时,它正确使用此repo,但随后将结果缓存在常春藤缓存中。 Is there an incantation I can tell Ivy/sbt to not do this? 有没有咒语我可以告诉Ivy / sbt不这样做? Perhaps something in ivysettings.xml? 也许在ivysettings.xml中有什么东西?

@kheraud -> clean /reload/ update -> will not work sbt caches it localy and do not check again for new snapshot in local maven @kheraud - >清理/重新加载/更新 - >不会工作sbt缓存它本地并且不再检查本地maven中的新快照

@dprat -> I have been looking for solution in web and haven't found anything more :( I gave up - just delete your local package in ivy cache and do play update you can simplify it and make a script @dprat - >我一直在寻找网络解决方案,还没有找到更多:(我放弃了 - 只需删除你在常春藤缓存中的本地包,并play update你可以简化它,并制作一个脚本

rm -rf ~/.ivy2/cache/your.package.foo
play update compile

Elsewhere I've seen this ascribed to an SBT defect https://groups.google.com/forum/?fromgroups=#!topic/play-framework/O7_cAdUWQII 在其他地方,我看到这归因于SBT缺陷https://groups.google.com/forum/?fromgroups=#!topic/play-framework/O7_cAdUWQII

One solution seems to be to use Nexus. 一种解决方案似乎是使用Nexus。 You will have to deploy from maven to nexus. 您将不得不从maven部署到nexus。 You will have to use the nexus path instead of mvn. 您将不得不使用nexus路径而不是mvn。 You will have to install and run nexus! 你必须安装并运行nexus!

To install nexus go to sonatype and download. 要安装nexus,请转到sonatype并下载。 Watch file permissions (read the instructions) but it is simple. 监视文件权限(阅读说明)但很简单。 You will need to put the credentials in ~/.m2/settings.xml. 您需要将凭据放在〜/ .m2 / settings.xml中。 Default is admin, admin123. 默认为admin,admin123。

<settings>
  <servers>
    <server>
      <id>snapshots</id>
      <username>admin</username>
        <password>admin123</password>
    </server>
  </servers>
</settings>

The maven deploy is given to you by nexus, eg: maven部署由nexus提供给你,例如:

<distributionManagement>
    <repository>
        <id>releases</id>
        <url>http://0.0.0.0:8081/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://0.0.0.0:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

Then mvn deploy will put your resource there. 然后mvn deploy将把你的资源放在那里。

Then in the play sbt use 然后在播放sbt使用

resolvers += "Local Nexus Repository" at "http://0.0.0.0:8081/nexus/content/repositories/snapshots"

You still need to stop play, use play update, and restart play. 您仍然需要停止播放,使用播放更新,然后重新开始播放。

You can use: 您可以使用:

  • play reload // Reload the current application build file play reload //重新加载当前的应用程序构建文件
  • play update // Update application dependencies play update //更新应用程序依赖项

before building your application. 在构建应用程序之前。 I don't know if you can configure sbt to not cache the SNAPSHOT dependencies, but you can script your building process to force reloading dependencies. 我不知道您是否可以将sbt配置为不缓存SNAPSHOT依赖项,但您可以编写构建过程的脚本以强制重新加载依赖项。

I'm not sure how this works, but "another guy told me" - yes, that's the extent of my references for this - that cleaning out the "repository" folder in the play installation might help. 我不确定这是如何工作的,但是“另一个人告诉我” - 是的,这是我对此的引用程度 - 清除播放安装中的“repository”文件夹可能有所帮助。

I have a little "refresh.sh" script that does this: 我有一个“refresh.sh”脚本,它执行此操作:

rm -rf /opt/play/repository/cache/com.mycompany
play clean
play update
play run

It seems to work for me. 它似乎对我有用。 Where "/opt/play" is where you have your play installation and "com.mycompany" is what you need to refresh. 其中“/ opt / play”是您安装游戏的地方,“com.mycompany”是您需要刷新的地方。

I'm not saying this is right, but it might be worth of shot if nothing else works. 我不是说这是对的,但如果没有别的办法,它可能值得一试。

As of sbt version 0.13.6 (Aug 2014), one can use build settings flag updateOptions in Build.scala/build.sbt , to control SNAPSHOT resolution. 从sbt版本0.13.6(2014年8月)开始,可以在Build.scala/build.sbt使用构建设置标志updateOptions来控制SNAPSHOT分辨率。

updateOptions := updateOptions.value.withLatestSnapshots(false/true)

Documentation about this new feature is here 有关此新功能的文档在此处

Corresponding pull request on github for details. github上的相应pull请求有关详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM