How to exclude java source files in doc task?
Asked Answered
P

1

12

I'm using sbt 0.11.2 for a mixed Java/Scala project. I've realized that when I run the doc command from within sbt, it does not only create the scaladocs for the Scala source files in src/main/scala, but also for the Java source files in src/main/java (the sbt wiki claims to create them for src/main/scala only that seems not true).

However, this does not look very well. For instance, for a Java class named Foo with static methods there are two entries in the generated scaladoc: a Foo class and a Foo object. The class only lists the constructor and the object lists the static methods.

Is there any way I can tell sbt to exclude the src/main/java folder from the scaladoc generation? I want to create javadocs for those instead.

Peritonitis answered 16/1, 2012 at 18:52 Comment(0)
W
12

The usual way to handle that is to use inspect to see where the information is coming from, and then change it. Inspecting at doc shows compile:sources(for doc), which is a Seq[java.io.File], and can be changed like this:

sources in (Compile, doc) ~= (_ filter (_.getName endsWith ".scala"))

You can use show compile:sources(for doc) to see what it contains, and then set to change it and check again its value.

Wart answered 17/1, 2012 at 14:57 Comment(3)
Thanks Daniel, adding this line to my project's build.sbt solves the problem. Unfortunately, SBT's documentation is quite superficial in explaining each feature and configuring advanced settings like this one is not for Scala beginners like me. Hopefully, more attention will be paid to the entire documentation aspect of Scala and its libraries.Peritonitis
@PeterStahl I beg to disagree. The SBT documentation covers this extensively -- at the quickstart, and then again in the advanced topics. It teaches pretty much the approach above: how to discover workings of a task, and then how to override it. I know this, because it's been barely a month since I had to dig deeper than basic settings, and all of the above I learned on the SBT wiki.Wart
I agree that the necessary information can be found on this page. However, it's difficult for me to adapt its content to new problems. The didactical preparation of the SBT wiki could be better. Especially more examples would clarify a lot of things. Apart from that, I was merely talking about Scala's documentation situation in general, not just SBT. Anyway, this is not the right place to discuss this, so let's just finish here. Thanks again!Peritonitis

© 2022 - 2024 — McMap. All rights reserved.