Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt: publish generated sources

Tags:

scala

sbt

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?

like image 752
0__ Avatar asked Nov 17 '15 14:11

0__


People also ask

What does sbt publish do?

The publish action is used to publish your project to a remote repository. To use publishing, you need to specify the repository to publish to and the credentials to use. Once these are set up, you can run publish .

Where are sbt dependencies stored?

Solution. You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

What is Ivy in sbt?

sbt (through Ivy) verifies the checksums of downloaded files by default. It also publishes checksums of artifacts by default. The checksums to use are specified by the checksums setting.

What are resolvers in sbt?

sbt resolver is the configuration for repository that contains jars and their dependencies. for example the below is a resolver definition for a repository called Sonatype and it points at snapshot releases (dev versions) resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"


3 Answers

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) }
}
like image 84
0__ Avatar answered Oct 20 '22 00:10

0__


mappings in (Compile,packageSrc) := (managedSources in Compile).value map (s => (s,s.getName)),
like image 25
pfn Avatar answered Oct 19 '22 23:10

pfn


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))
}
like image 21
Michael Pollmeier Avatar answered Oct 19 '22 23:10

Michael Pollmeier