2

I can successfully compile my maven project using both Kotlin and Java. However javadoc is giving an error because it cannot find a symbol (corresponding to a Kotlin interface) being used in other Java class. NOTE that maven is correctly compiling both types and I am only getting the error in javadocs.

Next are the configured plugins:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>3.0.1</version>
    <configuration>
        <source>8</source>
    </configuration>
    <executions>
        <execution>
            <id>attach-javadocs</id>
            <goals>
                <goal>
                    jar
                </goal>
            </goals>
        </execution>
    </executions>
</plugin>
...
<plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <executions>
            <execution>
                <id>compile</id>
                <phase>compile</phase>
                <goals>
                    <goal>compile</goal>
                </goals>
                <configuration>
                    <sourceDirs>
                        <source>src/main/java</source>
                        <source>src/main/kotlin</source>
                    </sourceDirs>
                </configuration>
            </execution>
            <execution>
                <id>test-compile</id>
                <phase>test-compile</phase>
                <goals>
                    <goal>test-compile</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <jvmTarget>${maven.compiler.target}</jvmTarget>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <executions>
            <!-- Replacing default-compile as it is treated specially by maven -->
            <execution>
                <id>default-compile</id>
                <phase>none</phase>
            </execution>
            <!-- Replacing default-testCompile as it is treated specially by maven -->
            <execution>
                <id>default-testCompile</id>
                <phase>none</phase>
            </execution>
            <execution>
                <id>java-compile</id>
                <phase>compile</phase>
                <goals> <goal>compile</goal> </goals>
            </execution>
            <execution>
                <id>java-test-compile</id>
                <phase>test-compile</phase>
                <goals> <goal>testCompile</goal> </goals>
            </execution>
        </executions>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
</plugins>
...

2 Answers 2

1

Replacing javadocs plugin by the jetbrains dokka plugin suppresses the error, but it generates docs only for Java classes and is missing the Kotlin classes.

<plugin>
    <groupId>org.jetbrains.dokka</groupId>
    <artifactId>dokka-maven-plugin</artifactId>
    <version>1.9.10</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>dokka</goal>
                <goal>javadoc</goal>
                <goal>javadocJar</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm facing the same error. Kotlin classes are not generated by dokka neither in dokka nor in javadoc formats. Although the docs says the multilanguage is not supported just for JavaDoc — see kotlinlang.org/docs/…
0

Actually, I managed to add Kotlin classes to dokka generation in html dokka format (and also in dokkaJavadoc format!) by setting both source directories to it:

            <plugin>
                <groupId>org.jetbrains.dokka</groupId>
                <artifactId>dokka-maven-plugin</artifactId>
                <version>${maven-dokka-plugin.version}</version>
                <executions>
                    <execution>
<!--                        <phase>pre-site</phase>-->
                        <phase>package</phase>
                        <goals>
                            <goal>dokka</goal>
                            <goal>javadoc</goal>
                        </goals>
                    </execution>
                </executions>

                <!-- this is the trick! -->             
                <configuration>
                    <sourceDirectories>
                        <dir>${project.basedir}/src/main/kotlin</dir>
                        <dir>${project.basedir}/src/main/java</dir>
                    </sourceDirectories>
                </configuration>
            </plugin>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.