diff --git a/ivy/src/main/scala/sbt/Resolver.scala b/ivy/src/main/scala/sbt/Resolver.scala index 91368abfc..9ba5d56ce 100644 --- a/ivy/src/main/scala/sbt/Resolver.scala +++ b/ivy/src/main/scala/sbt/Resolver.scala @@ -300,18 +300,19 @@ object Resolver { def localBasePattern = "[organisation]/[module]/" + PluginPattern + "[revision]/[type]s/[artifact](-[classifier]).[ext]" def defaultRetrievePattern = "[type]s/[organisation]/[module]/" + PluginPattern + "[artifact](-[revision])(-[classifier]).[ext]" final val PluginPattern = "(scala_[scalaVersion]/)(sbt_[sbtVersion]/)" - private[this] def mavenLocalDir: File = - { - val homeConfig = XML.loadFile(new File(Path.userHome, ".m2/settings.xml")) - homeConfig \ "settings" \ "localRepository" match { - case scala.xml.Text(x) => new File(x) - case _ => - val globalConfig = XML.loadFile(new File(Path.fileProperty("M2_HOME"), "conf/settings.xml")) - globalConfig \ "settings" \ "localRepository" match { - case scala.xml.Text(x) => new File(x) - case _ => new File(Path.userHome, ".m2/repository/") - } + private[this] def mavenLocalDir: File = { + def loadHomeFromSettings(f: () => File): Option[File] = + try { + XML.loadFile(f()) \ "settings" \ "localRepository" match { + case scala.xml.Text(loc) => Some(new File(loc)) + case _ => None + } + } catch { + case _: Throwable => None } + loadHomeFromSettings(() => new File(Path.userHome, ".m2/settings.xml")) orElse + loadHomeFromSettings(() => new File(Path.fileProperty("M2_HOME"), "conf/settings.xml")) getOrElse + new File(Path.userHome, ".m2/repository") } def publishMavenLocal = Resolver.file("publish-m2-local", mavenLocalDir) def mavenLocal = MavenRepository("Maven2 Local", mavenLocalDir.toURI.toString)