Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't use the Maven plug-in #181

Open
GeTOUO opened this issue Jul 10, 2019 · 17 comments
Open

I can't use the Maven plug-in #181

GeTOUO opened this issue Jul 10, 2019 · 17 comments

Comments

@GeTOUO
Copy link

GeTOUO commented Jul 10, 2019

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?

@SethTisue
Copy link
Member

sounds like #154?

@GeTOUO
Copy link
Author

GeTOUO commented Jul 10, 2019

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.

@SethTisue
Copy link
Member

what version of genjavadoc are you using?

@GeTOUO
Copy link
Author

GeTOUO commented Jul 11, 2019

I tried 0.11 and 0.13.

My POM configuration is as follows:

`



net.alchim31.maven
scala-maven-plugin
4.1.0


org.apache.maven.plugins
maven-compiler-plugin
3.8.1


    <!-- 标记源码目录和测试源码目录 -->
    <!--        <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
Copy link
Author

GeTOUO commented Jul 12, 2019

So what should I do?

@raboof
Copy link
Contributor

raboof commented Jul 12, 2019

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

@GeTOUO
Copy link
Author

GeTOUO commented Jul 12, 2019

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

@raboof
Copy link
Contributor

raboof commented Jul 12, 2019

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
Copy link
Contributor

raboof commented Jul 12, 2019

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 ?

@GeTOUO
Copy link
Author

GeTOUO commented Jul 12, 2019

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

@GeTOUO
Copy link
Author

GeTOUO commented Jul 12, 2019

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
Copy link
Author

GeTOUO commented Jul 15, 2019

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

`

@SethTisue
Copy link
Member

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

@GeTOUO
Copy link
Author

GeTOUO commented Jul 17, 2019

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}

@raboof
Copy link
Contributor

raboof commented Jul 17, 2019

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?

@GeTOUO
Copy link
Author

GeTOUO commented Jul 17, 2019

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
Copy link
Author

GeTOUO commented Jul 17, 2019

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants