Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaladoc options with Maven

I'm looking for help with the scala-maven-plugin for Maven. I would like to generate my Scaladoc but I'm having some problems with it.

I actually can create my Scaladoc typing the following command:

mvn scala:doc

The problem now is that I want to add some options when I generate the Scaladoc, such as -no-link-warnings.

Does anyone know how to do this? I have found a way (the code below works), but I don't think that's the way I should be done.

My pom file is:

<build>
    ...
    <plugins>
        <plugin>
            <!-- see http://davidb.github.com/scala-maven-plugin -->
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.2.1</version>
            <configuration>
                <args>
                    <arg>-no-link-warnings</arg>
                </args>
            </configuration>
            <executions>
                <execution>
                    <id>Compile</id>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                    <configuration>
                        <args>
                            <arg>-dependencyfile</arg>
                            <arg>${project.build.directory}/.scala_dependencies</arg>
                        </args>
                    </configuration>
                </execution>
            </executions>
        </plugin>
   ...
   </plugins>

EDIT

A better approach has been suggested by the user Tunaki on the first reply, you can see the code there.

like image 493
Rors Avatar asked Mar 14 '23 15:03

Rors


1 Answers

Your configuration is entirely correct, although you could write it a bit diffently. Currently (forgetting the part about compiling the sources), you have:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.1</version>
    <configuration>
        <args>
            <arg>-no-link-warnings</arg>
        </args>
    </configuration>
</plugin>

With such a configuration, you declare that every execution of the scala-maven-plugin will have the additional argument -no-link-warnings. This is because you are declaring it inside the global configuration element. You can have a configuration that is specific to an execution of the plugin, exactly like what you have for the compiling part:

<execution>
    <id>Compile</id>
    <goals>
        <goal>compile</goal>
        <goal>testCompile</goal>
    </goals>
    <configuration>
        <args>
            <arg>-dependencyfile</arg>
            <arg>${project.build.directory}/.scala_dependencies</arg>
        </args>
    </configuration>
</execution>

This configuration will only be taken into account when the execution Compile will be invoked.


As such, it would be preferable to change your configuration to be specific to an execution of the plugin, because the argument -no-link-warnings is really specific to generating the Scaladoc.

This would be the final plugin declaration:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.1</version>
    <executions>
        <execution>
            <id>Scaladoc</id>
            <goals>
                <goal>doc</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
                <args>
                    <arg>-no-link-warnings</arg>
                </args>
            </configuration>
        </execution>
        <execution>
            <id>Compile</id>
            <goals>
                <goal>compile</goal>
                <goal>testCompile</goal>
            </goals>
            <configuration>
                <args>
                    <arg>-dependencyfile</arg>
                    <arg>${project.build.directory}/.scala_dependencies</arg>
                </args>
            </configuration>
        </execution>
    </executions>
</plugin>

Then, when you package your project with mvn package for example, the Scaladoc will be automatically generated with the correct argument.

like image 136
Tunaki Avatar answered Mar 24 '23 16:03

Tunaki