Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Could not find proxy for val base" error in sbt 1.3.0 loading project

Tags:

scala

sbt

I upgraded to sbt 1.3.0 and related plugins.sbt. When I try to start sbt for my project it fails to initialize with the error

java.lang.IllegalArgumentException: Could not find proxy for val base: sbt.SettingKey in List(value base, method sbtdef$1, method $sbtdef, object $bd1712fb73ddc970045f, package <empty>, package <root>) (currentOwner= method $sbtdef )
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.searchIn$1(LambdaLift.scala:316)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.$anonfun$proxy$4(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.searchIn$1(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.$anonfun$proxy$4(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.searchIn$1(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.$anonfun$proxy$4(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.searchIn$1(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.$anonfun$proxy$4(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.searchIn$1(LambdaLift.scala:321)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.proxy(LambdaLift.scala:330)
[error]     at scala.tools.nsc.transform.LambdaLift$LambdaLifter.proxyRef(LambdaLift.scala:370)

I did find this stackoverflow question Could not find proxy for ... in Macro , but I don't think it helps my error.

i think the code perpetrator is

//Ensure that version.sbt is included with each package.
mappings in Universal ++= {
  val h=(packageBin in Compile, baseDirectory)
  val base=h._2
  val versionFile = (base.value / "version.sbt")
  versionFile.get.map(file => file -> file.name)
}

and for some reason base is not storing (packageBin in Compile, baseDirectory) properly?

Edit: I not a 100% but I think I fixed it by removing the intermediate variables and one lining it. So something like this:

mappings in Universal ++= {
((packageBin in Compile, baseDirectory)._2.value / "version.sbt").get.map(file => file -> file.name)
}

I don't know why it fixed it though...

like image 311
person personson Avatar asked Nov 07 '22 13:11

person personson


1 Answers

I think the OP has confused the example with the ineffectual tuple use; perhaps there is some misunderstanding with some SBT API/DSL usage, that is, packageBin in Compile is never used or resolved (for it's side-effect).

I believe the error, however, is more to do with expressing the mappings in Universal task value in way the macro cannot process - it gets confused - for instance, expecting the macro/compiler to find the taskKey in a variable base, which is the _2 in a Tuple2.

The example could be rewritten as

mappings in Universal ++= {
  (baseDirectory.value / "version.sbt").get.map(file => file -> file.name)
}

or

mappings in Universal ++= {
  (baseDirectory in(Compile, packageBin)).value / "version.sbt").get.map(file => file -> file.name)
}

Depending on what the intention was (probably the latter).

Of course the new syntax would be

mappings in Universal ++= {
  ((Compile / packageBin / baseDirectory).value / "version.sbt").get.map(file => file -> file.name)
}
like image 126
Darren Bishop Avatar answered Nov 15 '22 06:11

Darren Bishop