Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all default resolvers from a Play! application?

Background: our company has several Play! apps, which have their tests run in our internal CI. Each Play application retrieves dependencies from various public repositories over http. This has not been ideal (it bypasses our internal Nexus repository) but bearable. Now we are adding extra CI capacity, and do not want to allow the new machines to be able to access outside the firewall.

In an example Play app, the following configuration in project/Build.scala is not enough to prevent the build going to repo.typesafe.com and repo1.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 is our internal Nexus host, which proxies Maven Central, Typesafe, and others repositories)

When I remove some dependencies, either from Maven Central (e.g. Guava) or from Typesafe's repository (e.g. the Play mailer plugin), and run play compile, I see from the output that the dependencies are still being retrieved from repo.typesafe.com and repo1.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)

To compound the problem, we're also on slightly older versions of everything: Scala 2.9.1, Play 2.0.1, sbt 0.11.3.


How do I force a Play app to retrieve dependencies from an internal repository, exclusively?

like image 549
Grundlefleck Avatar asked Jul 05 '13 14:07

Grundlefleck


2 Answers

Turns out the answer is to use the correct sbt syntax.

The code listed in the question is generating configuration for the build, but not assigning it anywhere. I believed the := replaced the global config for the resolvers key, but it does not.

Putting the following in project/Build.scala forced the Play app to resolve dependencies from our internal 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
)

Note assigning the result of resolvers := to a new val, which is then added to the settings of the project in the same file:

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

Also, got rid of the sbtResolver and externalResolvers parts of the config, which had no effect.

like image 142
Grundlefleck Avatar answered Nov 10 '22 19:11

Grundlefleck


Edit or create /home/YOUR_HOME/.sbt/repositories add the following:

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

when running play add this parameter: -Dsbt.override.build.repos=true

e.g: activator run -Dsbt.override.build.repos=true

This prevents play from loading the repositories defined in project configs.

See this for details.

like image 41
vizog Avatar answered Nov 10 '22 21:11

vizog