0__
0__

Reputation: 67280

sbt: publish generated sources

I have a project where part of the sources are generated (sourceGenerators in Compile). I noticed that (in most scenarios reasonably) these sources are not published with publishLocal or publishSigned. In this case this is unfortunate because when you use this project/library as a dependency, you cannot look up the sources, for example in IntelliJ, even if the other sources of the project have been downloaded.

Can I configure sbt's publishing settings to include the generated sources in the Maven -sources.jar?

Upvotes: 10

Views: 1491

Answers (3)

Michael Pollmeier
Michael Pollmeier

Reputation: 1380

Just like @0__'s answer, but ported to the 'new' sbt syntax, i.e. without deprecation warnings.

Compile/packageSrc/mappings ++= {
  val base  = (Compile/sourceManaged).value
  val files = (Compile/managedSources).value
  files.map(f => (f, f.relativeTo(base).get.getPath))
}

Upvotes: 2

0__
0__

Reputation: 67280

So, just to be complete, this was my solution based on @pfn's answer:

mappings in (Compile, packageSrc) ++= {
  val base  = (sourceManaged  in Compile).value
  val files = (managedSources in Compile).value
  files.map { f => (f, f.relativeTo(base).get.getPath) }
}

Upvotes: 12

pfn
pfn

Reputation: 1830

mappings in (Compile,packageSrc) := (managedSources in Compile).value map (s => (s,s.getName)),

Upvotes: 7

Related Questions