Skip to content

Generating and Attaching of Scaladocs are broken with Scala3 #604

@chr78rm

Description

@chr78rm

The production of Scaladoc APIs are broken when using Scala3, e.g. with Scala 3.1.2:

<profile>
    <id>scala3-failure</id>
    <properties>
        <scala-maven-plugin.version>4.6.1</scala-maven-plugin.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>${scala-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>Scalac</id>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <args>
                                <arg>-deprecation</arg>
                                <arg>-release:17</arg>
                                <arg>-encoding</arg>
                                <arg>utf-8</arg>
                            </args>
                        </configuration>
                    </execution>
                    <execution>
                        <id>Scaladoc-jar</id>
                        <goals>
                            <goal>doc-jar</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala3-library_3</artifactId>
            <version>3.1.2</version>
        </dependency>
    </dependencies>
</profile>

This gives

$ mvn clean install -P scala3-failure
...
[INFO]
[INFO] --- maven-source-plugin:3.2.1:jar-no-fork (attach-sources) @ scaladoc-jar-test ---
[INFO] Building jar: C:\Users\Developer\Git\Git-2.36.0-64-bit\projects\scaladoc-jar-test\target\scaladoc-jar-test-0.0.1-sources.jar
[INFO]
[INFO] >>> scala-maven-plugin:4.6.1:doc-jar (Scaladoc-jar) > generate-sources @ scaladoc-jar-test >>>
[INFO]
[INFO] --- scala-maven-plugin:4.6.1:add-source (Scalac) @ scaladoc-jar-test ---
[INFO]
[INFO] <<< scala-maven-plugin:4.6.1:doc-jar (Scaladoc-jar) < generate-sources @ scaladoc-jar-test <<<
[INFO]
[INFO]
[INFO] --- scala-maven-plugin:4.6.1:doc-jar (Scaladoc-jar) @ scaladoc-jar-test ---
bad option '-doc-format:html' was ignored
bad option '-doc-title' was ignored
source file not found: scaladoc-jar-test 0.0.1 API
2 warnings found
1 error found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...

The issue can be reproduced with the build profile scala3-failure of the test project. The test project can be cloned by

git clone https://github.com/chr78rm/scaladoc-jar-test.git

The mentioned profile uses the currently promoted version (4.6.1) of the plugin and tries to attach scaladocs as depicted on the project site. I have investigated this a bit further. One reason why this cannot work is the wrong qualified class name given by the the method apidocMainClassName(). The correct qualified class name would be dotty.tools.scaladoc.Main. Using Scala3 this class is even separated from the scala compiler, that is an additional dependency (scaladoc_3) is needed to resolve this class. Unfortunately a potential fix in accordance with the outline of the given program structure of the plugin runs into classloader issues. scaladoc_3 uses the java.lang.ClassLoader.getResourceAsStream(String) method but it seems that the invocations prepared by e.g. JavaMainCallerByFork don't provide a class loader when calling getClassLoader(). I am not an expert in classloader issues but it might well be that this issue is inevitable when using the currently provided invocations within the scala_maven_executions package.

Nevertheless, I have prepared a possible fix within the forked repo

https://github.com/chr78rm/scala-maven-plugin

of your plugin. Checkout the branch scaladoc3. The prepared fix uses the ProcessBuilder of the JDK to invoke a forked process and reflects as far as possible the given outline of the plugin code structure. The mentioned classloader issue can be triggered by checking out the branch classloader-issue. Both mentioned branches of the fork produce an artifact of the plugin with version 4.6.2-EXPERIMENTAL. This version is used by the other build profiles of the test project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions