These are chat archives for sbt/sbt

22nd
Dec 2016
marios iliofotou
@imarios
Dec 22 2016 01:17
hey guys, anyone knows if there is a way to tell to a project with an aggregate() to call a command (say "package") only on the aggregated projects and not on itself? I know how do the inverse (run on itself but not the aggregated).
thejonas
@thejonas
Dec 22 2016 16:50

In my build.sbt I have

    publish := {
      (test in Test).value
      publish.value
    }

to make the publish task also run tests. If I try to put the same thing in a plugin however,

override lazy val projectSettings = Seq(
    publish := {
      (test in Test).value
      publish.value
    })

the dependency is not set (or possibly overridden?). Anybody know what I need to do to make this work?

Edmondo Porcu
@edmondo1984
Dec 22 2016 19:19

I have a multi-module project where I publish A, and another multi module project where I depend on A in the following way:

libraryDependencies += ("myGroupId" %% "myArtifactId" % version % Test).classifier("tests") .

This second multi-module project does not compile because of an error like the following:
Could not access type KeepAliveRoutes in package a.b.c.d. The strange thing is that the exception is triggered by one test class, which is inside the same artifact as KeepAliveRoutes. So it looks like as the published test classes are not compiled against the version of the compile classes, I wonder how this is possible since I publish them together?!?

I am totally lost, any help is much appreciated
Brian Topping
@briantopping
Dec 22 2016 19:32
why is your dependency configuration Test instead of test?
I’ve never used classifier except in Maven to specify the artifact coordinate, so assuming that you set a classifer for the original jar where it is built.
there’s some way to look at what’s defined in the console, but I’m no wiz at it.
I just fell across http://eed3si9n.com/sbt-010-guide which is filling a lot of gaps
Edmondo Porcu
@edmondo1984
Dec 22 2016 19:53
@briantopping might be a good point
so the point is that if you try to depend on other test artifacts, sbt fails saying configuration is private. I took that way of using a test artifact from a github issue
Brian Topping
@briantopping
Dec 22 2016 20:02
@edmondo1984 You’ll never get configuration from a separate build carrying over to a new build through an artifact dependency. That only occurs if you have a plugin that creates the configuration as a dependency of a TaskKey (if I am articulating that correctly)
make sure to differentiate the dependency on the static artifact with the inclusion of dynamic behavior, basically
the plugin is what gives you the latter
Edmondo Porcu
@edmondo1984
Dec 22 2016 20:07
@briantopping I used the "test"
but still the problem is the same
Brian Topping
@briantopping
Dec 22 2016 20:14
Hmm, it seems like you would get an error if the dependency was unresolved.
Grant
@gavares
Dec 22 2016 20:22
does anyone know the proper syntax for addCommandAlias in a Build.scala file? I've only ever used it in build.sbt before and can't seem to find any docs on how to apply it in a Builds.scala.
Brian Topping
@briantopping
Dec 22 2016 20:23
@edmondo1984: what does show test:dependencyClasspath say? Is your depenedency in there?
Grant
@gavares
Dec 22 2016 20:23
Is that a function on the root project of a multiproject build? If so, does it go in as a constructor arg?
Brian Topping
@briantopping
Dec 22 2016 20:23
@gavares I am also trying to discover the same thing with addArtifact
Edmondo Porcu
@edmondo1984
Dec 22 2016 20:24
yes it is there. let me summarize, I have the test jar of dependency A as a dependency of my module B.
SBT fails saying that it cannot load a class of compile jar of dependency A when running test of B
it very much looks like the test JAR of dependency A that I published is not compiled against the classes of A that the compile jar includes
which is akward because test-jar and compile-jar are published together
Brian Topping
@briantopping
Dec 22 2016 20:25
ohhhh I see what you are saying
If testA is built to run tests on compileA and testA cannot function for testB without compileA, you need to explicitly include compileA as a test scope dependency
Grant
@gavares
Dec 22 2016 20:27
@briantopping seems like both functions addCommandAlias and addArtifact are defined in BuildExtras.scala
Brian Topping
@briantopping
Dec 22 2016 20:27
You could generate testA to include compileA (or some subset), but it’s by design that they are kept separate
since you generaly want the build to fail if compile depends on test
Edmondo Porcu
@edmondo1984
Dec 22 2016 20:28
uhm !
excellent
let me see
@briantopping I like the idea, I hope it works
effectively there's nothing such as a maven-like dependency between testA and compileA
however, what's weird is that compileA is on the compile classpath of module B
Brian Topping
@briantopping
Dec 22 2016 20:30
you can also synthesize a dependency from testA to compileA in the A build and compileA should be included as a test scope dependency in Bs test environment
Edmondo Porcu
@edmondo1984
Dec 22 2016 20:30
uhm
Brian Topping
@briantopping
Dec 22 2016 20:30
which is probably what I’d do, but I don’t know how to do that
Edmondo Porcu
@edmondo1984
Dec 22 2016 20:30
the interesting thing I have observed
is that
if I do a test:update, the A-test.jar is not downloaded (it's a snapshot)
Brian Topping
@briantopping
Dec 22 2016 20:32
there must be some snapshot check timeout that is configured in the resolver
that’s pretty common
Grant
@gavares
Dec 22 2016 20:34
@briantopping I've figured out how to addCommandAlias in a Build.sbt file. My root project definition looks like:
  lazy val root = {
    val ss = commonSettings ++
      addCommandAlias("cc", "compile") ++
      addCommandAlias("ccc", ";clean; compile") ++
      addCommandAlias("refresh", ";reload; update") ++
      addCommandAlias("buildCluster", ";compile; tenantsService/stage; querySvc/stage; mosaik/stage") ++
      addCommandAlias("e2e", ";buildCluster; cluster/test") ++
      addCommandAlias("run", ";buildCluster; cluster/run")

    Project(
      id = "skeppare",
      base = file("."),
      settings = ss,
      aggregate = allProjects
    )
  }
Brian Topping
@briantopping
Dec 22 2016 20:34
oh that’s simple enough, thanks
Edmondo Porcu
@edmondo1984
Dec 22 2016 20:34
Summarizing. Module B depends on A.jar and depends on A-test.jar for testing. When launching tests, sbt complain about classes in A-test.jar compiled against a different version of the classes in A.jar
Grant
@gavares
Dec 22 2016 20:35
presumably addArtifact should be similar but you probably won't use ++ since it doesn't return a Seq[Setting[..]]
Brian Topping
@briantopping
Dec 22 2016 20:35
@gavares cool thanks :)
@edmondo1984 maybe verify it’s a resolver problem by doing a publishLocal in A, then trying your B build?
after getting that verified, determine why it’s not working with your repository properly
Edmondo Porcu
@edmondo1984
Dec 22 2016 20:40
@briantopping publishLocal of A and ATest, and offline:=true in the build of B?
I think SBT always updates snapshots
Brian Topping
@briantopping
Dec 22 2016 20:41
yes, I’m just being paranoid to get something working first, then learn from there
Brian Topping
@briantopping
Dec 22 2016 22:33
Is there a more idiomatic way to say the following? (not that this even works…)
val featureFile: TaskKey[File] = TaskKey[File]("feature")
featureFile := new sbt.File("src/main/feature/feature.xml")
val artifact: Def.Initialize[Artifact] = Def.setting {
  Artifact(moduleName.value, "xml", "xml", "features")
}
…
    addArtifact(artifact, featureFile).settings