How to generate an aggregated scaladoc for a maven site?

不打扰是莪最后的温柔 提交于 2019-12-03 03:17:32

This doesn't answer the question exactly as asked, but is a solution that may actually be preferred for mixed java/scala projects until ScalaDoc is capable of parsing JavaDoc comments. It produces a single aggregated JavaDoc that includes documentation from all of the project's Scala source files as well.

The solution is simple: configure Maven to use the GenJavaDoc Scala compiler plugin so that ScalaDocs can be converted to JavaDocs. Then, use the normal javadoc:aggregate goal to aggregate the project as normal.

Here is a sample Maven profile to do this. It configures the Scala compiler to generate the JavaDocs corresponding to the Scala sources, configures Maven to treat the genjavadoc directory created by the Scala compiler as a source directory, and then configures the javadoc plugin itself (this last may be optional if you have no special JavaDoc plugin configuration requirements).

<profile>
  <id>javadoc</id>
  <build>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>doc</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <args>
            <arg>-P:genjavadoc:out=${project.build.directory}/genjavadoc</arg>
          </args>
          <compilerPlugins>
            <compilerPlugin>
              <groupId>com.typesafe.genjavadoc</groupId>
              <artifactId>genjavadoc-plugin_${scala.binary.full.version}</artifactId>
              <version>0.4</version>
            </compilerPlugin>
          </compilerPlugins>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/genjavadoc</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <minmemory>64m</minmemory>
          <maxmemory>2g</maxmemory>
          <outputDirectory>${project.build.directory}</outputDirectory>
          <detectLinks>true</detectLinks>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!