Play 2.0 and SNAPSHOT dependencies
Asked Answered
S

5

14

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.

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.

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. On the maven side, I do the following

mvn clean install

which (of course) builds and installs my external artifact to my local maven repository (at ~/.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. 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. I've got the following in my 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. Is there an incantation I can tell Ivy/sbt to not do this? Perhaps something in ivysettings.xml?

Specter answered 25/7, 2012 at 6:19 Comment(2)
Does #8225407 help?Aggravate
Yes - I've tried every combination I can think of. A vanilla play 2.0 install caches SNAPSHOTS and you have to manually delete them. Using sbt 0.11 (without play installed) does the same. Additionally, using sbt 0.12 with the latest Play 2.1 SNAPSHOT exhibits this as well. No matter what I do, the SNAPSHOT is cached in ~/.ivy2/cache and no manner of sbt/play incantation can cause sbt/play to update this SNAPSHOT in the ivy cache.Specter
L
6

@kheraud -> clean /reload/ update -> will not work sbt caches it localy and do not check again for new snapshot in local 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

rm -rf ~/.ivy2/cache/your.package.foo
play update compile
Loxodrome answered 11/3, 2013 at 16:13 Comment(0)
G
2

Elsewhere I've seen this ascribed to an SBT defect https://groups.google.com/forum/?fromgroups=#!topic/play-framework/O7_cAdUWQII

One solution seems to be to use Nexus. You will have to deploy from maven to nexus. You will have to use the nexus path instead of mvn. You will have to install and run nexus!

To install nexus go to sonatype and download. Watch file permissions (read the instructions) but it is simple. You will need to put the credentials in ~/.m2/settings.xml. Default is 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, e.g.:

<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.

Then in the play sbt use

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.

Gammon answered 8/5, 2013 at 14:16 Comment(0)
B
1

You can use:

  • play reload // Reload the current application build file
  • play update // Update application dependencies

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.

Baker answered 26/7, 2012 at 8:13 Comment(0)
C
0

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.

I have a little "refresh.sh" script that does this:

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.

I'm not saying this is right, but it might be worth of shot if nothing else works.

Ceyx answered 3/7, 2014 at 13:2 Comment(0)
R
0

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.

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

Documentation about this new feature is here

Corresponding pull request on github for details.

Rolandrolanda answered 17/10, 2016 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.