genjavadoc icon indicating copy to clipboard operation
genjavadoc copied to clipboard

I can't use the Maven plug-in

Open GeTOUO opened this issue 5 years ago • 17 comments

I can't compile: My environment is Maven3.6 + scala2.12.8 + java1.8 For example, I have a class like this: case class AreaModel(code: String, name: String, level: String, parent: String, code_short: String) run compile and gened AreaModel.java and AreaModel$.java but, Maven throws some errors similar to: abstract and static: static public abstract boolean canEqual (Object that) ; How should I solve it?

GeTOUO avatar Jul 10 '19 11:07 GeTOUO

sounds like #154?

SethTisue avatar Jul 10 '19 14:07 SethTisue

Yes, but I don't know how to solve this problem. I used spring-auto-restdocs and a lot of scala case class in my project, the spring-auto-restdocs only parse javadoc. I rely on scaladoc to output the restapi description.

GeTOUO avatar Jul 10 '19 17:07 GeTOUO

what version of genjavadoc are you using?

SethTisue avatar Jul 10 '19 20:07 SethTisue

I tried 0.11 and 0.13.

My POM configuration is as follows:

` <pluginManagement> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> 4.1.0 <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> 3.8.1 </pluginManagement>

    <!-- 标记源码目录和测试源码目录 -->
    <!--        <sourceDirectory>src/main/scala</sourceDirectory>-->
    <!--        <testSourceDirectory>src/test/scala</testSourceDirectory>-->
    
    <plugins>
        <!-- http://davidb.github.io/scala-maven-plugin/ -->
        <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>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>scala-test-compile</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>testCompile</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.11</version>
                    </compilerPlugin>
                </compilerPlugins>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/main/scala</source>
                            <source>src/main/java</source>
                            <source>${project.build.directory}/genjavadoc</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/scala</source>
                            <source>src/test/java</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <charset>UTF-8</charset>
                <encoding>UTF-8</encoding>
                <docencoding>UTF-8</docencoding>
                <minmemory>64m</minmemory>
                <maxmemory>2g</maxmemory>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <detectLinks>true</detectLinks>
            </configuration>
            <executions>
                <execution>
                    <id>generate-javadoc-json</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>javadoc-no-fork</goal>
                    </goals>
                    <configuration>
                        <doclet>capital.scalable.restdocs.jsondoclet.ExtractDocumentationAsJsonDoclet</doclet>
                        <docletArtifact>
                            <groupId>capital.scalable</groupId>
                            <artifactId>spring-auto-restdocs-json-doclet</artifactId>
                            <version>2.0.5</version>
                        </docletArtifact>

                        <destDir>generated-javadoc-json</destDir>
                        <!-- 不支持 <additionalparam>-d "${project.build.outputDirectory}"</additionalparam>-->
                        <reportOutputDirectory>${project.build.directory}</reportOutputDirectory>
                        <useStandardDocletOptions>false</useStandardDocletOptions>
                        <show>package</show>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>`

GeTOUO avatar Jul 11 '19 02:07 GeTOUO

So what should I do?

GeTOUO avatar Jul 12 '19 09:07 GeTOUO

#156 should have been fixed in 0.12, so if you're still seeing the problem with 0.13 then either that didn't completely fix the issue or what you are seeing is a different issue.

A useful next step could be to put together and share a "reproducer" project that shows the problem. That would be a very helpful starting point for someone to look further into the problem.

Perhaps a bit more complicated, reproducing the problem as a genjavadoc test case would also be great.

raboof avatar Jul 12 '19 09:07 raboof

Thank you for your reply.

I uploaded a demo to reproduce the error.

Please have a look.

genjavadoc-error-demo https://github.com/GeTOUO/genjavadoc-error-demo.git

GeTOUO avatar Jul 12 '19 09:07 GeTOUO

The first problem I noticed is that the empty package is not handled correctly in a generic type parameter, I added that as a separate issue under #182

raboof avatar Jul 12 '19 10:07 raboof

When I add a package, indeed I see errors like:

[ERROR] /home/aengelen/dev/genjavadoc-error-demo/target/genjavadoc/foo/ScalaModel.java:[7,29] illegal combination of modifiers: abstract and static
[ERROR] /home/aengelen/dev/genjavadoc-error-demo/target/genjavadoc/foo/ScalaModel.java:[7,36] cannot find symbol
  symbol:   class T1
  location: class foo.ScalaModel
[ERROR] /home/aengelen/dev/genjavadoc-error-demo/target/genjavadoc/foo/ScalaModel.java:[7,27] cannot find symbol
  symbol:   class R
  location: class foo.ScalaModel
[ERROR] /home/aengelen/dev/genjavadoc-error-demo/target/genjavadoc/foo/ScalaModel$.java:[2,9] foo.ScalaModel$ is not abstract and does not override abstract method apply(java.lang.String) in scala.Function1
[ERROR] /home/aengelen/dev/genjavadoc-error-demo/target/genjavadoc/foo/ScalaModel.java:[6,9] foo.ScalaModel is not abstract and does not override abstract method apply(T1) in foo.ScalaModel
[ERROR] /home/aengelen/dev/genjavadoc-error-demo/target/genjavadoc/foo/ScalaModel.java:[32,35] toString() in foo.ScalaModel cannot override toString() in java.lang.Object

While these are definitely errors, perhaps the problem here is that we try to compile those sources at all. genjavadoc has some known limitations that prevent it from producing actually-correct Java code. It just creates Java code that is 'correct enough' to be able to use it as the basis to create javadocs.

The problem might be that you're adding the generated sources to your 'main' project with the build-helper-maven-plugin, rather than just for the 'javadoc' profile as shown on https://github.com/lightbend/genjavadoc . Would it be possible to use a profile like described there and at https://stackoverflow.com/questions/12301620/how-to-generate-an-aggregated-scaladoc-for-a-maven-site/16288487#16288487 ?

raboof avatar Jul 12 '19 10:07 raboof

em, In the generated Java class: static public abstract R apply (T1 v1) ; static and abstract are conflicting

GeTOUO avatar Jul 12 '19 10:07 GeTOUO

Okay, I'll take a look at the links you provide, because using this project is looking to inject other operations into the process of creating Javadoc to generate other data.

GeTOUO avatar Jul 12 '19 10:07 GeTOUO

I wonder if it is possible for plug-ins to provide an extensible interface that injects scaladoc-like abstractions into the scope of the interface. Then can users define other behaviors or side effects? It's like slick's CodeGen. I think it's good that users can extend some behavior and transform the data they need, and be more flexible in dealing with scaladoc and Javadoc tag compatibility. ` class CustomDocData(doc: ScalaDocModel ) extend Default(doc) { val hook = }

`

GeTOUO avatar Jul 15 '19 18:07 GeTOUO

I wonder if it is possible for plug-ins to provide an extensible interface that injects scaladoc-like abstractions into the scope of the interface

I don't understand what you mean by that. but also, probably this issue tracker isn't the place to discuss it

SethTisue avatar Jul 15 '19 19:07 SethTisue

Thanks to @SethTisue and @raboof's help. I modified a little Maven configuration to avoid the compilation process. Now I can use this library to generate the data I need. Finally, my configuration is as follows:

            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <...>
                <configuration>
                    <args>
                        <arg>-P:genjavadoc:out=${project.build.directory}/genjavadoc</arg>
                        <arg>-encoding</arg>
                        <arg>UTF-8</arg>
                    </args>
                    <compilerPlugins>
                        <compilerPlugin>
                            <groupId>com.typesafe.genjavadoc</groupId>
                            <artifactId>genjavadoc-plugin_${scala.binary.full.version}</artifactId>
                            <version>0.13</version>
                        </compilerPlugin>
                    </compilerPlugins>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>generate-javadoc-json</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>javadoc-no-fork</goal>
                        </goals>
                        <configuration>
                            <doclet>capital.scalable.restdocs.jsondoclet.ExtractDocumentationAsJsonDoclet</doclet>
                            <docletArtifact>
                                <groupId>capital.scalable</groupId>
                                <artifactId>spring-auto-restdocs-json-doclet</artifactId>
                                <version>2.0.5</version>
                            </docletArtifact>
                            <sourcepath>${project.build.directory}\genjavadoc\com\scst; ${project.basedir}</sourcepath>
                            <destDir>generated-javadoc-json</destDir>
                            <reportOutputDirectory>${project.build.directory}</reportOutputDirectory>
                            <useStandardDocletOptions>false</useStandardDocletOptions>
                            <show>package</show>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

${project.build.directory}\genjavadoc\com\scst; ${project.basedir}

GeTOUO avatar Jul 17 '19 09:07 GeTOUO

Good to hear you managed to get it to work! Is this something that we could/should document better, or was it specific to your project?

raboof avatar Jul 17 '19 10:07 raboof

I think it can be adjusted to make it easier to use.

Instead of using build-helper-maven-plugin to add genjavadoc's output directory as the source directory, I added genjavadoc's output directory to maven-javadoc-plugin's configuration. Now Javadoc can work in the compile stage, avoiding trying to compile the code generated by genjavadoc.

GeTOUO avatar Jul 17 '19 10:07 GeTOUO

like this:

    <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.11</version>
            </compilerPlugin>
          </compilerPlugins>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <minmemory>64m</minmemory>
          <maxmemory>2g</maxmemory>
          <sourcepath>${project.build.directory}\genjavadoc; ${project.basedir}</sourcepath>
          <outputDirectory>${project.build.directory}</outputDirectory>
          <detectLinks>true</detectLinks>
        </configuration>
      </plugin>
    </plugins>
  </build>

GeTOUO avatar Jul 17 '19 10:07 GeTOUO