如何为maven站点生成聚合scaladoc?

时间:2012-09-06 13:50:16

标签: scala maven maven-site-plugin scala-maven-plugin

我有一个多模块Maven构建,我想在我的根模块中生成一个聚合的Scaladoc,类似于maven-javadoc-plugin的聚合目标。我的第一次尝试是:

<project ...>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <configuration>
                        <reportPlugins>
                            <plugin>
                                <artifactId>maven-project-info-reports-plugin</artifactId>
                            </plugin>
                            <plugin>
                                <groupId>net.alchim31.maven</groupId>
                                <artifactId>scala-maven-plugin</artifactId>
                                <reports>
                                    <report>doc</report>
                                </reports>
                                <configuration>
                                    <aggregateDirectOnly>false</aggregateDirectOnly>
                                    <sendJavaToScalac>false</sendJavaToScalac>
                                </configuration>
                            </plugin>
                            <plugin>
                                <artifactId>maven-javadoc-plugin</artifactId>
                                <reports>
                                    <report>aggregate</report>
                                </reports>
                            </plugin>
                        </reportPlugins>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

但是,aggregateDirectOnly属性似乎没有任何效果。我总是只为个别罐型POM获得Scaladoc。

我也尝试将forceAggregate设置为true,但它也没有效果。

怎么做?

1 个答案:

答案 0 :(得分:6)

这并不像所要求的那样回答完全这个问题,但是在ScalaDoc能够解析JavaDoc注释之前,它实际上是混合java / scala项目的首选解决方案。它生成一个聚合的JavaDoc,包含来自所有项目的Scala源文件的文档

解决方案很简单:配置Maven以使用GenJavaDoc Scala编译器插件,以便可以将ScalaDocs转换为JavaDocs。然后,使用正常javadoc:aggregate目标正常聚合项目。

以下是一个示例Maven配置文件。它配置Scala编译器生成与Scala源对应的JavaDocs,将Maven配置为将Scala编译器创建的genjavadoc目录视为源目录,然后配置javadoc插件本身(如果最后,则可以选择您没有特殊的JavaDoc插件配置要求。)

<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>