我有一个非常基本的sbt项目,除了一个.java
文件之外的所有scala代码,我需要生成一个标准的javadoc网页。
我试图按照the plugin's README上的说明操作。我已经复制了&#34之后的所有代码;集成到SBT构建中非常简单,"它将变量JavaDoc
和javadocSettings
定义到我的build.sbt
文件中,并添加了以下内容:
resolvers += "Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases/"
autoCompilerPlugins := true
说明说我必须"将{] javadocSettings
添加到Project
。"我不知道这意味着什么。这就是README中的代码所做的,还是我需要做的事情?如果是这样,怎么样?
无论如何,README继续:"可以使用genjavadoc:doc
生成JavaDoc。"然而,在sbt
我看到了:
> genjavadoc:doc
[error] No such setting/task
[error] genjavadoc:doc
[error] ^
>
我错过了什么?
答案 0 :(得分:2)
您需要在插件的README.md
中进行配置。您的任务调用无效,因为sbt。
genjavadoc
您必须按照插件文档中的说明添加它。在您的build.sbt
文件中添加插件推荐的以下内容(保留您已经拥有的内容):
lazy val JavaDoc = config("genjavadoc") extend Compile
lazy val javadocSettings = inConfig(JavaDoc)(Defaults.configSettings) ++ Seq(
libraryDependencies += compilerPlugin("com.typesafe.genjavadoc" %% "genjavadoc-plugin" % "0.7" cross CrossVersion.full),
scalacOptions <+= target map (t => "-P:genjavadoc:out=" + (t / "java")),
packageDoc in Compile <<= packageDoc in JavaDoc,
sources in JavaDoc <<= (target, compile in Compile, sources in Compile) map ((t, c, s) =>
(t / "java" ** "*.java").get ++ s.filter(_.getName.endsWith(".java"))),
javacOptions in JavaDoc := Seq(),
artifactName in packageDoc in JavaDoc :=
((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar")
)
但是要使其工作,您需要将配置和设置添加到项目中。最简单的方法是在build.sbt
添加一行额外的行:
lazy val root = project.in(file(".")).configs(JavaDoc).settings(javadocSettings: _*)
现在您应该能够使用genjavadoc:doc
生成javadoc。
鉴于上述情况,完整的build.sbt
可能如下所示:
resolvers += "Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases/"
lazy val root = project.in(file(".")).configs(JavaDoc).settings(javadocSettings: _*)
lazy val JavaDoc = config("genjavadoc") extend Compile
lazy val javadocSettings = inConfig(JavaDoc)(Defaults.configSettings) ++ Seq(
libraryDependencies += compilerPlugin("com.typesafe.genjavadoc" %% "genjavadoc-plugin" % "0.7" cross CrossVersion.full),
scalacOptions <+= target map (t => "-P:genjavadoc:out=" + (t / "java")),
packageDoc in Compile <<= packageDoc in JavaDoc,
sources in JavaDoc <<= (target, compile in Compile, sources in Compile) map ((t, c, s) =>
(t / "java" ** "*.java").get ++ s.filter(_.getName.endsWith(".java"))),
javacOptions in JavaDoc := Seq(),
artifactName in packageDoc in JavaDoc :=
((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar")
)
PS。小额奖励,如果您使用的是比0.13.2更新的sbt,则可以定义javadocSettings
而不使用<<=
和<+=
以及其他类似的操作符:
lazy val javadocSettings = inConfig(JavaDoc)(Defaults.configSettings) ++ Seq(
addCompilerPlugin("com.typesafe.genjavadoc" %% "genjavadoc-plugin" % "0.7" cross CrossVersion.full),
scalacOptions += s"-P:genjavadoc:out=${target.value}/java",
packageDoc in Compile := (packageDoc in JavaDoc).value,
sources in JavaDoc :=
(target.value / "java" ** "*.java").get ++ (sources in Compile).value.filter(_.getName.endsWith(".java")),
javacOptions in JavaDoc := Seq(),
artifactName in packageDoc in JavaDoc :=
((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar")
)