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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With