如何强制SBT使用Javadoc而不是Scaladoc?

时间:2014-08-24 07:35:04

标签: scala sbt

我有基于Java的Play&使用SBT构建的Akka项目,有什么方法可以告诉SBT在构建项目时运行Javadoc而不是Scaladoc? SBT文件说明了

  

“如果项目中只有Java源代码,sbt将运行javadoc。如果有任何Scala源,sbt将运行scaladoc。“

并且项目中没有Scala文件,但仍然运行Scaladoc。我认为这是因为Play插件在编译发生之前将视图模板和conf/routes文件转换为Scala代码。

3 个答案:

答案 0 :(得分:3)

tl; dr 更改sources in (Compile, doc)以排除*.scala个文件,因此scaladoc无法启动。

正如您在下面可以阅读的那样sources in (Compile, doc)保存项目中的所有来源,包括托管和非托管

> inspect compile:doc::sources
[info] Task: scala.collection.Seq[java.io.File]
[info] Description:
[info]  All sources, both managed and unmanaged.

通过一些filter,您可以轻松实现目标 - 在build.sbt中使用以下内容:

sources in (Compile, doc) <<= sources in (Compile, doc) map { _.filterNot(_.getName endsWith ".scala") }

示例项目的会话(//的评论是我的,以加强阅读):

// display current setting's value
> show compile:doc::sources
[info] ArrayBuffer(/Users/jacek/sandbox/sbt-learning-space/src/main/scala/x.scala, /Users/jacek/sandbox/sbt-learning-space/src/main/java/Hello.java)
[success] Total time: 0 s, completed Aug 24, 2014 9:31:34 PM

// generate docs - scaladoc kicks in since there are scala files
> doc
[info] Updating {file:/Users/jacek/sandbox/sbt-learning-space/}sbt-learning-space...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Main Scala API documentation to /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api...
model contains 3 documentable templates
[info] Main Scala API documentation successful.
Hello
[success] Total time: 1 s, completed Aug 24, 2014 9:32:15 PM

// change the value of sources in the current session only - use session save to retain it
> set sources in (Compile, doc) <<= sources in (Compile, doc) map { _.filterNot(_.getName endsWith ".scala") }
[info] Defining compile:doc::sources
[info] The new value will be used by compile:doc
[info] Reapplying settings...
[info] Set current project to hello (in build file:/Users/jacek/sandbox/sbt-learning-space/)

// display current setting's value - it only holds the single java file
> show compile:doc::sources
[info] ArrayBuffer(/Users/jacek/sandbox/sbt-learning-space/src/main/java/Hello.java)
[success] Total time: 0 s, completed Aug 24, 2014 9:33:23 PM

// generate docs - javadoc is properly generated
> doc
[info] Main Java API documentation to /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api...
[info] Loading source file /Users/jacek/sandbox/sbt-learning-space/src/main/java/Hello.java...
[info] Constructing Javadoc information...
[info] Standard Doclet version 1.7.0_65
[info] Building tree for all the packages and classes...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/Hello.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/package-frame.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/package-summary.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/package-tree.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/constant-values.html...
[info] Building index for all the packages and classes...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/overview-tree.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/index-all.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/deprecated-list.html...
[info] Building index for all classes...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/allclasses-frame.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/allclasses-noframe.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/index.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/help-doc.html...
[info] Main Java API documentation successful.
Hello
[success] Total time: 1 s, completed Aug 24, 2014 9:34:01 PM

答案 1 :(得分:1)

scala 2.12.0-RC1 (Sept. 2016)SI 4826允许的另一种方法是让scaladoc运行!它将处理javadoc评论!

  

Scaladoc已经处理了Java源代码并为它们生成了Scaladoc   它只是忽略了文档评论。

     

由于各种原因,我们的许多Scala代码库至少都有一些Java   如果Scaladoc可以为这些混合代码库生成完整的文档,包括所有文档注释,那就太好了。

答案 2 :(得分:0)

您可以尝试将genjavadoc集成到sbt中,以生成javadoc。

  

仍然可以使用正常的doc任务生成ScalaDoc   而JavaDoc可以使用 genjavadoc:doc 生成。