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

Some project dependencies are missing when scanning the project #25

Closed
tosix1988 opened this issue Apr 25, 2019 · 2 comments
Closed

Some project dependencies are missing when scanning the project #25

tosix1988 opened this issue Apr 25, 2019 · 2 comments

Comments

@tosix1988
Copy link
Contributor

When the swagger-maven-plugin scans the project for swagger resources, the classloader it uses to load classes is missing the scanned project's dependencies, and thus may fail with ClassNotFoundException or similar. This can be worked around by explicitly listing all dependencies of the project in plugin's dependencies section, but for large projects there can be many dependencies, so adding all required ones may be tedious, and the plugin should handle this automatically if possible.

I have put up a simple project that demonstrates this: swagger-maven-project-with-dependencies.zip

I think this can be solved by not adding just project.getBuild().getOutputDirectory() to the URLClassLoader, but also the resources provided by project.getCompileClasspathElements() and project.getRuntimeClasspathElements().

@langecode
Copy link
Member

Hmm... Been a while since I looked into this but the Mojo is actually declared as @Mojo(name = "generate", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) I would have thought the requiresDependencyResolution also included classpath but from your observation this seems wrong. I do think I previously did an example where endpoints came from submodules but it may have been broken along the way.

I will look into this - but I agree that these should be included by default.

@tosix1988
Copy link
Contributor Author

I think that requiresDependencyResolution just guarantees that if you will request the classpath artifacts during the MOJO execution, Maven will resolve the artifacts in respective scopes before the MOJO executes (so that they are already resolved when you ask for them), otherwise various classpath resource methods MavenProject provides might throw DependencyResolutionRequiredException.

Btw. I have created a pull request that attempts to fix this issue (it fixed the issue on my test project, I hope it would work in general).

langecode pushed a commit that referenced this issue May 5, 2019
* fix creation of plugin's classloader

add all compile and runtime dependencies as URL resources
of the URLClassLoader.

* explicitly include build directory to the dependencies
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

2 participants