These are chat archives for sbt/sbt

26th
Oct 2016
Mirco Dotta
@dotta
Oct 26 2016 10:06

Hi All, I'm working on a sbt autoplugin and I'd like to inject settings to a project iff some other setting's value evaluate to true. Here is some code to show the rough idea of what I'd like to do:

object FooPlugin extends AutoPlugin  {
  object autoImport {
    val injectProjectSettings = settingKey[Boolean]("flag")
  }

  override lazy val projectSettings = {
    if(injectProjectSettings.value) myProjectSettings
    else Seq.empty
  }

  def myProjectSettings: Seq[Def.Setting[_]] = ???
}

Any hint/idea on how I could achieve this would be highly appreciated :)

Mirco Dotta
@dotta
Oct 26 2016 10:11
The problem with the above solution is that injectProjectSettings.value can only be evaluated within a task/setting.
Julien Richard-Foy
@julienrf
Oct 26 2016 11:11
@dotta Looks like you are looking for Def.taskDyn
(or Def.settingDyn)
Dale Wijnand
@dwijnand
Oct 26 2016 11:15
That's individual settings. You can't define a seq of settings dynamically
Sadly
Julien Richard-Foy
@julienrf
Oct 26 2016 11:19
@dotta but looking at your example, isn’t it simpler to ask users to do enablePlugins(FooPlugin) or disablePlugins(FooPlugin) instead of injectProjectSettings := true?
Mirco Dotta
@dotta
Oct 26 2016 11:26
@julienrf Thanks for chiming in. I'm wondering how a taskDyn could help me with the above, could you elaborate. Asking users to remove the plugin is a possibility, but I'd prefer to avoid it (as I'd like to place the plugin in global and then disable it only on specific projects)
Julien Richard-Foy
@julienrf
Oct 26 2016 11:26
No, actually, as @dwijnand said, xxxDyn works only for one key, not for seqs of keys
Mirco Dotta
@dotta
Oct 26 2016 11:27
Oh, I see @dwijnand was hinting it's not possible to use a dynTask/dynSetting for a seq of settings, which is what I thought
right
Dale Wijnand
@dwijnand
Oct 26 2016 11:28
use disablePlugins in your specific projects
Mirco Dotta
@dotta
Oct 26 2016 11:28
mmm, that's interesting
do you think I can have a task that, when called, disables the plugin
I'd like to make it really easy for users to do it
actually, maybe calling a task is more cumbersome than just editing the build and reloading
Dale Wijnand
@dwijnand
Oct 26 2016 11:29
you can't anyways
Mirco Dotta
@dotta
Oct 26 2016 11:30
but I could hack into sbt state, i.e., I could have a project's setting injectProjectSettings and then use its value in the plugin's onLoad to side-effect the plugins enabled for a project
Dale Wijnand
@dwijnand
Oct 26 2016 11:33
I don't think you can, plugins are evaluated before project settings are evaluated
Mirco Dotta
@dotta
Oct 26 2016 11:35
I think you are right, as otherwise users wouldn't be able to override defaults provided by plugins
Nayana Hettiarachchi
@devzer01
Oct 26 2016 13:03
i am having the hardest time trying to include an unmanaged jar file to a project that has sub-project structure, i placed the file in /lib as suggested in sbt manual, and it's not been included when i run compile from sbt command line, (works fine on IDEA, since i included manually) i tried using both unmanagedBase := baseDirectory.value / "lib", unmanagedJars in Compile += file("sqlijdbc42.jar"),
and no success :worried:
Dale Wijnand
@dwijnand
Oct 26 2016 13:13
@devzer01 add it to the lib directory in the project directory you want to add the library too, not the root
Nayana Hettiarachchi
@devzer01
Oct 26 2016 13:13
ah you mean lib in sub-project?
ok gonna try that thanks :)
Dale Wijnand
@dwijnand
Oct 26 2016 13:14
np
mahe-ymc
@mahe-ymc
Oct 26 2016 13:24
I'm trying to write a Task which executes another Task. That works fine. What does not work is aggregation of the Task I'm executing within my Task. Is that expected to work out of the box?
Nayana Hettiarachchi
@devzer01
Oct 26 2016 13:26
thanks @dwijnand works like a charm :)
Dale Wijnand
@dwijnand
Oct 26 2016 13:26
np
mahe-ymc
@mahe-ymc
Oct 26 2016 13:26
So for example when I execute myTask in a project scope which aggregates other projects, the task I run within myTask is not run within the aggregated projects.
Dale Wijnand
@dwijnand
Oct 26 2016 13:27
@mahe-ymc let's call the task you're running within myTask task2: you need to sure task2 is defined in each project you're aggregating on
mahe-ymc
@mahe-ymc
Oct 26 2016 13:29
Hm, I think it is. For example when task2 is: (test in Test).value. But it's not propagated to the other ones
Dale Wijnand
@dwijnand
Oct 26 2016 13:30
try and minimise the problem, you'll find you either understand the reason, or you'll have something minimal you can share
mahe-ymc
@mahe-ymc
Oct 26 2016 13:34
lazy val minimized = taskKey[Unit]("")
minimized := {
  (test in Test).value
}
Tests are run on my root project only but not in the aggregated ones
Dale Wijnand
@dwijnand
Oct 26 2016 13:52
there's no aggregation in that example
mahe-ymc
@mahe-ymc
Oct 26 2016 13:58
I defined the aggregation on my root project
mahe-ymc
@mahe-ymc
Oct 26 2016 15:01
Solved it by using all and something like ScopeFilter(inProjects(root.aggregate().referenced: _*), inConfigurations(Test)). Thanks anyway
Ferdinand Svehla
@fsvehla
Oct 26 2016 16:23
Can I watch multiple tasks without having them linked? I currently use this: ~;frontend/fastOptJS;backend/re-start - but it leads to changes in either the frontend or backend codebase to trigger both tasks.
Perry
@pfn
Oct 26 2016 16:28
@fsvehla no
@fsvehla ~ uses watchSources from currentRef (current project selected in session)
Ferdinand Svehla
@fsvehla
Oct 26 2016 16:33
OK, I’ve tried to to make a new task in the global project that depends on both of those, but it seems they don’t have the right type - https://gist.github.com/fsvehla/08bdfc9316189f46c9e0d96fa3d2068b#file-build-sbt-L44
Are there any other options? Except using multiple SBT sessions
Perry
@pfn
Oct 26 2016 16:34
triggering will always run both
unless you do your own dirty-check to see if the tasks needs to run
but that's up to you to implement within your task
Ferdinand Svehla
@fsvehla
Oct 26 2016 16:34
Thanks, multiple sessions it is :)
Jim Schubert
@jimschubert
Oct 26 2016 21:37
does anyone know of a way to run sbt inside a docker container with support for triggered execution so I can do local changes in intellij? I've found https://github.com/brikis98/docker-osx-dev, but it doesn't seem to work with native docker on OS X.
Devis Lucato
@dluc
Oct 26 2016 22:25
hi @all, I was wondering if there is a way to do a "sbt publish" without the build phase ? I want sbt to publish my own jars, rather than those generated by the compilation
Perry
@pfn
Oct 26 2016 22:40
@dluc I typically do mvn deploy:deploy-file for that
Devis Lucato
@dluc
Oct 26 2016 22:45
@pfn I'll give that a try, hopefully it supports the cross compiled jars - thanks
Perry
@pfn
Oct 26 2016 22:46
do sbt publishM2 and use the generated pom files
deploy-file + corresponding pom + jar works fine
mvn deploy:help -Dgoal=deploy-file -Ddetail=true
Jim Kleckner
@jkleckner
Oct 26 2016 23:50
Anyone have experience with the sbt-git-stamp plugin or alternatives that you like? https://github.com/hmrc/sbt-git-stamp
Devis Lucato
@dluc
Oct 26 2016 23:58
can't say that I have but I'll definitely look at that, I need to correlate artifacts to dcs more