Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to override setting from extra project #5661

Open
steinybot opened this issue Jun 30, 2020 · 3 comments
Open

Unable to override setting from extra project #5661

steinybot opened this issue Jun 30, 2020 · 3 comments

Comments

@steinybot
Copy link
Contributor

steps

project/HammerPlugin.scala:

import sbt._

object HammerPlugin extends AutoPlugin {

  object autoImport {

    val cantTouchThis = settingKey[String]("Override this if you can.")
  }

  import autoImport._

  private val mcProject = Project("mc", file("."))
    .configure(p => p.in(file("target") / "dynamic-projects" / p.id))
    .settings(cantTouchThis := "Can't touch this!")

  override def extraProjects: Seq[Project] = Seq(mcProject)
}

build.sbt

enablePlugins(PrayPlugin)

cantTouchThis in LocalProject("mc") := "This doesn't work."

sbt:

sbt:bug-reports> show mc/cantTouchThis
[info] Can't touch this!

problem

All the normal ways of overriding settings do not seem to work on projects from plugins that are added via extraProjects.

expectation

sbt:

sbt:bug-reports> show mc/cantTouchThis
[info] This doesn't work.

notes

There is a reproduction with a few other things that I have tried in https://github.com/steinybot/bug-reports/tree/sbt/extra-project-settings.

@steinybot steinybot added the Bug label Jun 30, 2020
@steinybot
Copy link
Contributor Author

This works around the problem:

lazy val updateExtraProject: State => State = { s: State =>
  val projectID = "mc"
  val value = "Finally!"
  if (Project.extract(s).get(LocalProject(projectID) / cantTouchThis) == value)
    s
  else s"""set (LocalProject("$projectID") / cantTouchThis) := "$value"""" :: s
}

Global / onLoad := {
  val old = (Global / onLoad).value
  updateExtraProject compose old
}

@eed3si9n
Copy link
Member

I'm guessing it's something to do with Load.scala

val initialProjects = defsScala.flatMap(b => projectsFromBuild(b, normBase)) ++ buildLevelExtraProjects

Maybe you could try flipping the order in the above.

@steinybot
Copy link
Contributor Author

That didn't seem to make any difference.

I also noticed that extra projects are added to the build even if the plugin is not enabled on any other project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants