OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] maven-compile-plugin fails with missing symbol errors after openapi-generator-maven-plugin generated the sources

Open
#8,298 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When copying the plugin-Block from the Usage-Example of the openapi-generator-maven-plugin's README into a completely empty POM and executing mvn clean compile as instructed, the execution fails when the maven-compiler-plugin tries to compile the newly generated sources and, of course, can't find the packages referenced in those sources, such as gson, okio, etc.:

...
[ERROR] [...]\src\gen\java\main\org\openapitools\client\ApiClient.java:[23,22] error: package org.threeten.bp does not exist
[ERROR] [...]\src\gen\java\main\org\openapitools\client\ApiClient.java:[24,22] error: package org.threeten.bp does not exist
[ERROR] [...]\src\gen\java\main\org\openapitools\client\ApiClient.java:[25,29] error: package org.threeten.bp.format does not exist
[ERROR] [...]\src\gen\java\main\org\openapitools\client\ApiClient.java:[74,12] error: cannot find symbol
[ERROR] [...]\src\gen\java\main\org\openapitools\client\ApiClient.java:[77,12] error: cannot find symbol
...

So the plugin basically does what it's supposed to do, but the Maven compiler afterwards seems to be thrown off by the newly introduced code. The Plugin's README unfortunately does not seem to be addressing this issue.

Am I supposed to manually add those dependencies to my root POM and retry compiling until it works or am I missing some crucial configuration or knowledge about Maven's lifecycle?

Since the plugin generates a full project including POM which has those dependencies defined, I expected them to be transitively installed during compilation, but this does not seem to be the case. Even if they're installed in my local repository, I get the same error.

openapi-generator version

Tried with version 5.0.0 and any version above and including 4.0.0

Maven Version: 3.0.5
Java Version: 1.8.0_202

OpenAPI declaration file content or url

To test, I've used the official v3.0 Petstore example right from the master-Branch here on GitHub. I expect this spec to be valid and it seems to be, as the actual generation is not the problem.

Generation Details

A miminum sample repository can be found here.

The only step executed here is mvn clean compile.

Steps to reproduce
  1. Clone the sample repository / set up a minimum configuration for the Maven plugin against any valid spec to generate Java
  2. Execute mvn clean compile
Related issues/PRs

I've looked for both, open and closed issues containing the terms "maven", "plugin", and "symbol", but could not find any issues that seem to describe my issue. So I think what I'm experiencing is simply a configuration error, but I can't explain what I've missed since I didn't actually configure anything.

Suggest a fix

Unfortunately, I have only very little experience with Maven plugins and code generation with them in particular, so I don't know what to look for, here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Usage example in modules/openapi-generator-maven-plugin/README.md and reproduce the failure in the linked minimum sample repository with mvn clean compile. Compare the generated Java sources and their referenced dependencies with the empty POM and the generated project POM. Done means the documented setup compiles the generated sources without missing-package or missing-symbol errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.