openapi-processor / openapi-processor-maven

maven plugin to run any openapi-processor
https://docs.openapiprocessor.io/maven
Apache License 2.0
7 stars 2 forks source link

Illegal module access error while running on JDK 17 with Maven #2

Closed cdprete closed 2 years ago

cdprete commented 2 years ago

Hi. I wanted to test your plugin to see if it fits my needs, but when I try to use it it crashes with the following error:

[ERROR] Failed to execute goal io.openapiprocessor:openapi-processor-maven-plugin:2021.1:process (spring) on project test: Execution spring of goal io.openapiprocessor:openapi-processor-maven-plugin:2021.1:process fail
ed: An API incompatibility was encountered while executing io.openapiprocessor:openapi-processor-maven-plugin:2021.1:process: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x70616
22) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x7061622
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>io.openapiprocessor:openapi-processor-maven-plugin:2021.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/openapiprocessor/openapi-processor-maven-plugin/2021.1/openapi-processor-maven-plugin-2021.1.jar
[ERROR] urls[1] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/openapiprocessor/openapi-processor-spring/2021.5/openapi-processor-spring-2021.5.jar
[ERROR] urls[2] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.5.21/kotlin-stdlib-jdk8-1.5.21.jar
[ERROR] urls[3] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.5.21/kotlin-stdlib-1.5.21.jar
[ERROR] urls[4] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar
[ERROR] urls[5] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.5.21/kotlin-stdlib-common-1.5.21.jar
[ERROR] urls[6] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.5.21/kotlin-stdlib-jdk7-1.5.21.jar
[ERROR] urls[7] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/openapiprocessor/openapi-processor-core/2021.5/openapi-processor-core-2021.5.jar
[ERROR] urls[8] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/antlr/antlr4/4.9.2/antlr4-4.9.2.jar
[ERROR] urls[9] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/antlr/antlr4-runtime/4.9.2/antlr4-runtime-4.9.2.jar
[ERROR] urls[10] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2.jar
[ERROR] urls[11] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/antlr/ST4/4.3/ST4-4.3.jar
[ERROR] urls[12] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/abego/treelayout/org.abego.treelayout.core/1.0.3/org.abego.treelayout.core-1.0.3.jar
[ERROR] urls[13] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.jar
[ERROR] urls[14] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/ibm/icu/icu4j/61.1/icu4j-61.1.jar
[ERROR] urls[15] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/fasterxml/jackson/module/jackson-module-kotlin/2.12.3/jackson-module-kotlin-2.12.3.jar
[ERROR] urls[16] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.12.3/jackson-databind-2.12.3.jar
[ERROR] urls[17] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.12.3/jackson-core-2.12.3.jar
[ERROR] urls[18] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.12.3/jackson-annotations-2.12.3.jar
[ERROR] urls[19] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.4.21/kotlin-reflect-1.4.21.jar
[ERROR] urls[20] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/openapi4j/openapi-parser/1.0.7/openapi-parser-1.0.7.jar
[ERROR] urls[21] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/openapi4j/openapi-core/1.0.7/openapi-core-1.0.7.jar
[ERROR] urls[22] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.12.1/jackson-dataformat-yaml-2.12.1.jar
[ERROR] urls[23] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar
[ERROR] urls[24] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/swagger/parser/v3/swagger-parser/2.0.27/swagger-parser-2.0.27.jar
[ERROR] urls[25] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/swagger/parser/v3/swagger-parser-v3/2.0.27/swagger-parser-v3-2.0.27.jar
[ERROR] urls[26] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/swagger/core/v3/swagger-models/2.1.10/swagger-models-2.1.10.jar
[ERROR] urls[27] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/swagger/core/v3/swagger-core/2.1.10/swagger-core-2.1.10.jar
[ERROR] urls[28] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/jakarta/xml/bind/jakarta.xml.bind-api/2.3.2/jakarta.xml.bind-api-2.3.2.jar
[ERROR] urls[29] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/jakarta/activation/jakarta.activation-api/1.2.1/jakarta.activation-api-1.2.1.jar
[ERROR] urls[30] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.1/jackson-datatype-jsr310-2.12.1.jar
[ERROR] urls[31] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar
[ERROR] urls[32] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/swagger/parser/v3/swagger-parser-core/2.0.27/swagger-parser-core-2.0.27.jar
[ERROR] urls[33] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/apache/commons/commons-text/1.9/commons-text-1.9.jar
[ERROR] urls[34] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/apache/commons/commons-lang3/3.11/commons-lang3-3.11.jar
[ERROR] urls[35] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/commonmark/commonmark/0.17.0/commonmark-0.17.0.jar
[ERROR] urls[36] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/google/googlejavaformat/google-java-format/1.10.0/google-java-format-1.10.0.jar
[ERROR] urls[37] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/networknt/json-schema-validator/1.0.57/json-schema-validator-1.0.57.jar
[ERROR] urls[38] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar
[ERROR] urls[39] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar
[ERROR] urls[40] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
[ERROR] urls[41] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar
[ERROR] urls[42] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/checkerframework/checker-qual/3.8.0/checker-qual-3.8.0.jar
[ERROR] urls[43] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/google/errorprone/error_prone_annotations/2.5.1/error_prone_annotations-2.5.1.jar
[ERROR] urls[44] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar
[ERROR] urls[45] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.jar
[ERROR] urls[46] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar
[ERROR] urls[47] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/io/openapiprocessor/openapi-processor-api/2021.1/openapi-processor-api-2021.1.jar
[ERROR] urls[48] = file:/C:/Users/Cosimo%20Damiano%20Prete/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

Plugin configuration in Maven

<plugin>
                    <groupId>io.openapiprocessor</groupId>
                    <artifactId>openapi-processor-maven-plugin</artifactId>
                    <version>2021.1</version>
                    <dependencies>
                        <dependency>
                            <groupId>io.openapiprocessor</groupId>
                            <artifactId>openapi-processor-spring</artifactId>
                            <version>2021.5</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <apiPath>${project.basedir}/src/main/resources/service-contract.yaml</apiPath>
                    </configuration>
                    <executions>
                        <execution>
                            <id>spring</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <id>spring</id>
                                <options>
                                    <values>
                                        <targetDir>${project.basedir}/target/generated-sources/openapi</targetDir>
                                        <parser>OPENAPI4J</parser>
                                        <showWarnings>true</showWarnings>
                                    </values>
                                </options>
                            </configuration>
                            <goals>
                                <goal>process</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

This is probably caused by https://github.com/google/google-java-format#jdk-16

hauner commented 2 years ago

Yes, that is really annoying.

Not sure I can do anything about it apart from removing the formatter...

(see also: https://github.com/openapi-processor/openapi-processor-core/issues/79) I should probably move that info to the docs.

hauner commented 2 years ago

... another workaround would be an option to skip the formatting step. It is generated code, so we do not have to read it very often.

cdprete commented 2 years ago

... another workaround would be an option to skip the formatting step. It is generated code, so we do not have to read it very often.

How can I do it? Moreover, is there a way to generate just the models (without the API)?

hauner commented 2 years ago

disable formatting

I'm working on it. It is not possible with the current release.

What I found is that you can create a .mvn/jvm.config file in you project and add the exports to it:

--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

I checked it with the sample project and it works.

just generate models

There is no option to generate models only. It is generating only models which are in use, i.e. used by a interface method.

Best you can do is to ignore the generated interfaces.

cdprete commented 2 years ago

I'll give it a try

cdprete commented 2 years ago

Hi. While that suggestion fixed the issue with the module system from the JDK, it seems like the project is not able to properly generate all the models. From the Maven execution I get the following output:

[INFO] Changes detected - generating target files!
[INFO] using OPENAPI4J parser
[INFO] ref BasicContactDetails 1
[INFO] ref BasicContactDetails 2
[INFO] ref ContactsPostRequestBody 1
[INFO] ref BasicContactDetails 3
[INFO] ref SingleContactRead 1
[INFO] ref BasicContactDetails 4
[INFO] ref ContactsIdPutRequestBody 1
[INFO] ref BasicContactDetails 5

with just BasicContactDetails and SingleContactRead being generated when I should, instead, get other models as well. For example:

    ContactRead:
      type: object
      description: Object providing all the information about a contact in the system without e-mail addresses and phone numbers.
      allOf:
        - $ref: '#/components/schemas/BasicContactDetails'
      required:
        - id
      properties:
        id:
          $ref: '#/components/schemas/Id'
        image:
          $ref: '#/components/schemas/Image'

Also, the classes are wrongly generated when composing a model with multiple allOf. For example, given:

    SingleContactRead:
      type: object
      description: Object providing all the information about a single contact in the system, including e-mail addresses and phone numbers.
      allOf:
        - $ref: '#/components/schemas/ContactDetailsWithoutImage'
        - $ref: '#/components/schemas/ContactRead'
      required:
        - id
      properties:
        id:
          $ref: '#/components/schemas/Id'
        image:
          $ref: '#/components/schemas/Image'

I get the following class out:

/*
 * DO NOT MODIFY - this class was auto generated by openapi-processor-spring
 *
 * 2021.5
 * 2022-02-02T18:39:10.231468100Z
 * https://docs.openapiprocessor.io/spring
 */
package com.cdprete.phonebook.dto.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class SingleContactRead {

    @JsonProperty("name")
    private String name;

    @JsonProperty("surname")
    private String surname;

    @JsonProperty("name")
    private String name;

    @JsonProperty("surname")
    private String surname;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

}

Maybe I should specify something in the mapping.yaml file? I'm using the "empty" mapping

openapi-processor-mapping: v2

options:
  package-name: com.cdprete.phonebook.dto

That said, the original issue with this ticket is for me solved (or, at least, patched) and therefore I close this ticket. If you need more input about the other issues, just let me know ;)

hauner commented 2 years ago

oh, I guess you found some missing logic...

I don't have any tests for either case, so it is not implement... yet.

Looking at it, thanks for reporting :-)

hauner commented 2 years ago

... and no you don't need to configure anything in the mapping.yaml for this.

cdprete commented 2 years ago

Yes, name and surname are present in both the definitions. It would also be nice to have the mapping.yaml file being optional (implying the default content)

hauner commented 2 years ago

I have improved the processor. It recognizes the properties on the same level as the allOf and handles duplicate properties.

You can check this with version 2022.2-SNAPSHOT

Maven needs this to find the snapshot:

<project>
    <pluginRepositories>

        <pluginRepository>
            <id>openapi-processor-snapshots</id>
            <name>openapi-processor-snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </pluginRepository>

    </pluginRepositories>
<project>