9

I am trying to add sbt-native-packager plugin to my sbt build. For a number of reasons, I do not want my build to rely on default sbt repositories, I have blocked access to them on the network and added a resolver to my <project_home>/project/plugins.sbt in the following way:

resolvers += "local-repo-plugins" at "file:///" + baseDirectory.value + "/libs/repo/"
resolvers += Resolver.url("my-ivy-proxy-plugins", url("http://fullURLForRepo/"))(Patterns("[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]") )

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")

I can confirm the plugin it is hosted in my ivy proxy, but that is not even the issue, because sbt is still trying to go to default repos:

[info] Resolving com.typesafe.sbt#sbt-native-packager;0.7.4 ...
[error] Server access Error: Connection timed out url=https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-native-packager/scala_2.10/sbt_0.13/0.7.4/ivys/ivy.xml
[error] Server access Error: Connection timed out url=https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbt/sbt-native-packager/scala_2.10/sbt_0.13/0.7.4/ivys/ivy.xml
[error] Server access Error: Connection timed out url=https://repo1.maven.org/maven2/com/typesafe/sbt/sbt-native-packager_2.10_0.13/0.7.4/sbt-native-packager-0.7.4.pom

Also, this very same custom resolver works just fine (together with a couple of other ones, including one based on local filesystem) on my <project_home>/build.sbt when resolving library dependencies.

While I understand why the resolvers used in my project build are not the same used in my <project_home>/project/plugins.sbt, I have several questions regarding the issue I just described:

  1. Is this the right way to define resolvers for plugins? just adding them to the <project_home>/project/plugins.sbt with that syntax?
  2. If the answer to question 1) is yes: is there any way to avoid redundancy when defining these resolvers? e.g. I have defined exactly the very same ones in <project_home>/build.sbt
  3. And the most important: why is the sbt build not using my ivy proxy, as specified in the resolver, to retrieve the sbt-native-packager plugin?

3 Answers 3

3
  1. Yes this is a correct way to define your resolvers for plugins

  2. This is actually quite tricky : you are trying to share settings between the plugins build and the build. These are "separate" projects from sbt's perspective. There are solutions using a project ref to gain access to the plugins build settings from the build but they are quite tricky. If this is a corporate environment where you will never have access to the default repositories anyways, it might be easier to use a custom sbt.boot.properties. You can start from the default file for 0.13.x Changing the sbt.boot.properties should deliver you from the Server access errors.

  3. There is nothing in the logs you provide which indicates that the plugin failed to be resolved from your proxy, only that it timedout trying to reach the official repositories. With the default sbt.boot.properties, sbt will try to resolve artefacts in the order the resolvers are defined :

    local
    typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
    maven-central
    sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
    

    Then any resolver found in any .sbt files in the <project_home>/project/directory. As far as I am aware, sbt files are evaluated in the alphabetical order and resolvers are added in the order they appear in each file.

2
  • 1
    I accept this answer because even if it does not directly provides a solution to my problem, it correctly points out a problem with my question itself, as the logs pasted in are not complete nor indicative of the problem I am explaining. That in itself was a good hint of something I initially overlooked. Also the info and links in this answer are extremely informative and helpful (especially in its second point). Thanks!
    – djsecilla
    Dec 3, 2015 at 10:34
  • Sorry I couldn't be of more help, I hope you solve your problem. Please come back and post a better answer once you do :) (I think you can then change the accepted answer)
    – Jean
    Dec 3, 2015 at 10:44
2

It seems the documents are not updated yet which ask you to put resolvers in plugins.sbt. Moving resolvers ++= Seq("Artima Maven Repository" at "http://repo.artima.com/releases") to build.sbt fixes the issue.

0
1

I think that you guys got it all wrong, it should be like this:

my_project/project/plugins.sbt should have:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")

and my_project/project/project/build.sbt should have:

resolvers += ...

They are 2 different build definitions ...

3
  • That's not true. SBT is recursive, so the build itself is a project whose resolvers are customisable. Dec 2, 2017 at 21:20
  • I tested it before I answered, it's the only way it works for me.
    – lisak
    Dec 2, 2017 at 22:49
  • I'm not saying what you mentioned doesn't work. But you also implied that resolvers should not be in plugins.sbt, it should be essentially the same (putting it under project/project/build.sbt and under project/plugins.sbt). Dec 2, 2017 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.