These are chat archives for sbt/sbt

28th
May 2017
Kendall Shaw
@queshaw
May 28 01:16
when I run sbt new blah/blah.g8 it creates a skeleton project tree ./blah and next to it is a directory ./target (not within blah). Is there a reason for the target directory?
Sam Halliday
@fommil
May 28 08:14
Reason is a complex topic.
Guillaume Martres
@smarter
May 28 08:52
Can I have my State => State command mess with the state, then return back the old state, or is it supposed to be used linearly?
e.g., if I wanted to do something like ++ but that did not mess with the settings after it's done
Jorge
@jvican
May 28 10:18
hahaha, so many questions.
@fommil Have no idea how doge works. You should ask Eugene
@queshaw I see no reason why that target directory should be generated. I may be wrong though, i have no idea how g8 works.
@smarter It's supposed to be used linearly, but you can perfectly return the old state if that's what you want.
You have to be aware of the consequences: the state won't hold any result that could have been produced by ++. In fact, ++ will produce side effects but there won't be a proof that it was executed, so it's a way to silently execute things. I don't recommend this, though. Doesn't ++ go back to the previous scala version?
Guillaume Martres
@smarter
May 28 11:01
@jvican I wish it did
And you can't just manually go back to the previous version either, since ++ changes the scalaVersion for all projects
so if they use different versions, you can only restart sbt
Jorge
@jvican
May 28 11:02
Can you not keep a reference for the original scala version and set it yourself after ++ is executed?
Guillaume Martres
@smarter
May 28 11:02
for each subproject? Maybe, but that's complicated
Jorge
@jvican
May 28 11:02
yeah, you can, just store it inside State with put
Guillaume Martres
@smarter
May 28 11:03
restoring the previous State seems easier :)
Jorge
@jvican
May 28 11:03
i think the issue here is you're trying to work around a problem of the current ++ implementation
Guillaume Martres
@smarter
May 28 11:03
I don't think the new one fixes that, does it?
Jorge
@jvican
May 28 11:03
Why are you doing ++ instead of + command?
Guillaume Martres
@smarter
May 28 11:04
I'm not doing either
Jorge
@jvican
May 28 11:04
+ does restore the previous scala version
Guillaume Martres
@smarter
May 28 11:05
What I really want to do is enumerate all projects in the build, find the ones where scalaVersion starts with 0. and run some stuff on them, then find the ones where crossScalaVersion contains a version that starts with 0., run some stuff on them with this version set, then go back to the original state
if a project does not have a 0. version in its scalaVersion or crossScalaVersion, I don't want to do anything with it
Jorge
@jvican
May 28 11:06
okay, it doesn't seem difficult then :)
Guillaume Martres
@smarter
May 28 11:06
Please give me some example code that does that then :)
Jorge
@jvican
May 28 11:07
i will tomorrow :)
Guillaume Martres
@smarter
May 28 11:07
and I wil be eternally grateful
sure!
Jorge
@jvican
May 28 11:07
haha, yeah, don't worry, i'll look into it
it's difficult to get faimiliar with these sbt APIs, what you want is really an advanced use case
Guillaume Martres
@smarter
May 28 11:09
Li Haoyi
@lihaoyi
May 28 12:08
Is there a way to tell an SBT subproject to download source jars for all it's ivy dependencies and add them to the classpath?
I've been futzing around with (allDependencies in Test) ++= (allDependencies in Test).value.map(_ classifier "sources"), but it doesn't seem to do it
Jorge
@jvican
May 28 12:27
You will probably need to add them to the classpath manually, usually sources() works.
But for that you need to use updateClassifiers. By default, it downloads both sources and docs. You'll need to tweak it to only download docs.
Li Haoyi
@lihaoyi
May 28 12:31
I've got this so far
(allDependencies in Test) ++= {
      val thingy = (externalDependencyClasspath in Compile).value
      println(thingy)
      val flatMapped = thingy.flatMap(_.get(Keys.moduleID.key))
      println(flatMapped)
      flatMapped.map(_.classifier("sources"))
    }
Jorge
@jvican
May 28 12:33
allDependencies should contain both externalDependencyClasspath and projectDependencies, I think
let me have acloser look
Li Haoyi
@lihaoyi
May 28 12:39
yeah still poking
haven't gotten it working
Jorge
@jvican
May 28 12:39
Damn, I have to go now, but will look into it soon @lihaoyi. In the meanwhile, I suggest you have a look at the implementation of updateClassifiers
Li Haoyi
@lihaoyi
May 28 12:39
my goal is to have everything source-added to the classpath automatically in a small amount of time
Jorge
@jvican
May 28 12:39
also, can you try allDependencies.value.map(_.sources())?
Li Haoyi
@lihaoyi
May 28 12:39
@jvican yeah I saw some words about that on the internet somewhere
Jorge
@jvican
May 28 12:41
also, is there a reason why you're using the externalDependencyClasspath in Compile while you're scoping your implementation to Test?
Don't you want to depend on the externalDependencyClasspath in Test?
Li Haoyi
@lihaoyi
May 28 12:42
maybe
still futzing around :P
as I said it doesn't work
and I have no idea what I'm doing
debugging like
    (allDependencies in Test) ++= {
      val thingy = (externalDependencyClasspath in Compile).value
      println("THINGY: " + thingy)
      val flatMapped = thingy.flatMap(_.get(Keys.moduleID.key))
      println("FLATMAP: " + flatMapped)
      val sourced = flatMapped.map(_.classifier("sources"))
      println("SOURCED: " + sourced)
      sourced
    }
for some reason _.classifier("sources") seems to do nothing
and intellij is refusing to download SBT's sources so I can poke around, and the github project has changed enough that file seems to have disappeared
D=
or maybe it's working and the toString is confusing me
Jorge
@jvican
May 28 12:46
maybe
check it's working with update.value.allModules
and even better if you do update.value.{...}.allArtifacts
Li Haoyi
@lihaoyi
May 28 12:47
is there a way to running update.value.allModules from the SBT shell?
Jorge
@jvican
May 28 12:48
where {...} is configurations or something like that. You have to browse through its API, don't remember now.
just do show update
Li Haoyi
@lihaoyi
May 28 12:48
if I add a dependency on classifier "sources" do I still need to go and run updateClassifiers manually?
Jorge
@jvican
May 28 12:49
i don't know honestly, i'm not that familiar with it
first, i would use sources() just in case, it seems to do the same than classifier "sources" but I'm not sure about that
second, to me, intuitively, just doing update should work and get all your source artifacts
doing show update will show you everything about the update report, including the downloaded artifacts
and then, you'll know for sure whether that thing is correct or not
oops, show update does not show you the artifacts as i thought, it only does for sbt 1.0
this allDependencies := allDependencies.value.map(_.sources()) forced sbt to download sources for the gigahorse dependency @lihaoyi
but it seems that it's really where i run updateClassifiers where all dependencies are downloaded
Jorge
@jvican
May 28 12:54
ah no, it does show artifacts for sbt 0.13, but it didn't show them when i ran update. i only saw gigahorse-src successfully downloaded.
Li Haoyi
@lihaoyi
May 28 13:07
show updateClassifiers seems to show a bunch of stuff indicating source jars have been downloaded
[info]         org.scala-lang:scala-reflect:2.12.2:default:
[info]             (Artifact(scala-reflect,doc,jar,Some(javadoc),List(),Some(https://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.2/scala-reflect-2.12.2-javadoc.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.2/scala-reflect-2.12.2-javadoc.jar)
[info]             (Artifact(scala-reflect,src,jar,Some(sources),List(),Some(https://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.2/scala-reflect-2.12.2-sources.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.2/scala-reflect-2.12.2-sources.jar)
[info]         com.lihaoyi:sourcecode_2.12:0.1.3:default:
[info]             (Artifact(sourcecode_2.12,doc,jar,Some(javadoc),List(),Some(https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3-javadoc.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3-javadoc.jar)
[info]             (Artifact(sourcecode_2.12,src,jar,Some(sources),List(),Some(https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3-sources.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3-sources.jar)
[info]         com.github.scopt:scopt_2.12:3.5.0:default:
[info]             (Artifact(scopt_2.12,doc,jar,Some(javadoc),List(),Some(https://repo1.maven.org/maven2/com/github/scopt/scopt_2.12/3.5.0/scopt_2.12-3.5.0-javadoc.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/com/github/scopt/scopt_2.12/3.5.0/scopt_2.12-3.5.0-javadoc.jar)
[info]             (Artifact(scopt_2.12,src,jar,Some(sources),List(),Some(https://repo1.maven.org/maven2/com/github/scopt/scopt_2.12/3.5.0/scopt_2.12-3.5.0-sources.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/com/github/scopt/scopt_2.12/3.5.0/scopt_2.12-3.5.0-sources.jar)
[info]         org.scalaz:scalaz-concurrent_2.12:7.2.8:default:
[info]             (Artifact(scalaz-concurrent_2.12,doc,jar,Some(javadoc),List(),Some(https://repo1.maven.org/maven2/org/scalaz/scalaz-concurrent_2.12/7.2.8/scalaz-concurrent_2.12-7.2.8-javadoc.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/org/scalaz/scalaz-concurrent_2.12/7.2.8/scalaz-concurrent_2.12-7.2.8-javadoc.jar)
[info]             (Artifact(scalaz-concurrent_2.12,src,jar,Some(sources),List(),Some(https://repo1.maven.org/maven2/org/scalaz/scalaz-concurrent_2.12/7.2.8/scalaz-concurrent_2.12-7.2.8-sources.jar),Map()),/Users/lihaoyi/.coursier/cache/v1/https/repo1.maven.org/maven2/org/scalaz/scalaz-concurrent_2.12/7.2.8/scalaz-concurrent_2.12-7.2.8-sources.jar)
but i have no idea how to access them programmatically
Li Haoyi
@lihaoyi
May 28 13:27
uhh this seems to do it
(fullClasspath in Test) ++= {
      (updateClassifiers in Test).value
        .configurations
        .filter(_.configuration == "test")
        .head
        .modules.flatMap(_.artifacts.map(_._2))
    }
no idea if it's the right thing but it seems to do what I want
Jorge
@jvican
May 28 13:29
Yeah, right thing to do IMO
Sam Halliday
@fommil
May 28 16:04
@lihaoyi have a look in ensime-sbt for ideas
Li Haoyi
@lihaoyi
May 28 16:20
@fommil thanks, will tkae a look
Jorge
@jvican
May 28 16:42
@lihaoyi You asked before how you could run update.value.allModules from the sbt shell. Well, the answer is consoleProject and then you'll get a Scala REPL in which you can do update.eval.allModules. https://twitter.com/jvican/status/868869799585222656