【问题标题】:compilation error in POM, due to use of openApi usage for code generationPOM 中的编译错误,由于使用 openApi 生成代码
【发布时间】:2020-11-26 09:25:54
【问题描述】:

所以我使用的是 openApi 代码生成器。 (所有这些都适用于 Swagger 代码生成,同样的错误)

我在 Eclipse 中创建了一个 maven 项目,并且我有一个看起来像这样的 POM...

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test.api.openapi</groupId>
  <artifactId>test-openapi-codegen</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>test-openapi-codegen</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>
  
  <build>
   <plugins>
    <plugin>
     <groupId>org.openapitools</groupId>
     <artifactId>openapi-generator-maven-plugin</artifactId>
     <version>4.3.1</version>
     <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/openAPI.yaml</inputSpec>
                <generatorName>java</generatorName>
                <apiPackage>com.test.openapi.codegen.demo.api</apiPackage>
                <modelPackage>com.test.openapi.codegen.demo.model</modelPackage>
                <invokerPackage>com.test.openapi.codegen.demo</invokerPackage>
                <configOptions>
                <sourceFolder>src/java/</sourceFolder>
                </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.openapitools</groupId>
      <artifactId>openapi-generator-maven-plugin</artifactId>
      <version>4.3.1</version>
      <scope>provided</scope>
    </dependency> 
  </dependencies>
</project>

所以这个 POM 使用 YAML 文件来生成 JAVA 代码,YAML 文件充当要生成的代码的架构/结构文件。

这是一个链接:[https://openapi-generator.tech/docs/plugins/][1] -->我使用的插件在链接中提到。

因此,当我进行 mvn clean compile 时,代码将在 tag -> src/java/generated-code -> 中提到的输出文件夹中生成,如下所示。也正在为该生成的代码生成一个 POM,但是使用上面的命令“mvn clean compile”我得到以下错误,说缺少很多”包。阅读接下来的两行。

这里有一个问题,我检查了生成的 POM,并且依赖项正确存在于 POM 中,我也使用“MVN 编译”对其进行了测试,并且为该 POM 构建成功

 Changes detected - recompiling the module!
    [INFO] Compiling 43 source files to T:\Perforce\testStream\openapi-codegen\target\classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR :
    [INFO] -------------------------------------------------------------
    [ERROR] T:/Perforce/testStream/openapi-codegen/target/generated-sources/openapi/src/java/com/test/openapi/codegen/demo/model/ProvisioningBatch.java:[18,23] package com.google.gson does not exist

我做错了什么?我已经以最好的方式描述了。

【问题讨论】:

    标签: java maven openapi swagger-codegen openapi-generator


    【解决方案1】:

    我通过添加缺少的依赖项解决了这个问题,但我认为这不是最好的方法,最好使用 cli jar 来满足需要。

    从 maven Central 下载 jar,openapi-codegen-cli.jar 及其可运行的 jar,并根据要求使用参数。

    它将从 YAML 生成代码,然后您可以使用生成的 POM 进行 mvn clean install 或任何您想要的操作

    【讨论】:

      猜你喜欢
      • 2017-01-27
      • 2018-12-31
      • 2017-01-30
      • 1970-01-01
      • 2013-08-11
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      • 2021-05-22
      相关资源
      最近更新 更多