When a module being verified has a provided dependency on some other module that is required at compile time, then japicmp cannot load the classes from the first module because the provided dependency is not put on the classpath.
Steps to reproduce:
create a multi-module project with 2 modules
Module 1 contains some Interface
Module 2 contains a class implementing that interface
This happens because to generate the classpath The JapiCmpMojo is determining the set of dependencies via RepositorySystem#resolveDependencies in setUpClassPathUsingMavenProject(). However this does not give you all dependencies that the module needs to compile, but only those dependencies that another module depending on that module would need, and since provided (and optional) dependencies are not transitive they are not put on the classpath.
I couldn't find a nice way to solve this via the RepositorySystem API; the only alternative I could come up with is to use a custom DependencySelector that properly selects all dependencies that are required at compile time.
This selector would be used like this:
final DefaultRepositorySystemSession repositorySystemSession =
new DefaultRepositorySystemSession(mavenParameters.getRepoSession());
repositorySystemSession.setDependencySelector(new CompileScopeDependencySelector());
DependencyResult dependencyResult = mavenParameters.getRepoSystem().resolveDependencies(
repositorySystemSession,
new DependencyRequest(
request, (node, parents) -> true));
I'm still prototyping such a selector, but it should be something along the lines of:
Alternatively, it might be possible to get the original set of dependencies from the Maven model, and create a CollectRequest for those dependencies instead (i.e., pretend to be the module).
When a module being verified has a
provided
dependency on some other module that is required at compile time, then japicmp cannot load the classes from the first module because the provided dependency is not put on the classpath.Steps to reproduce:
provided
dependency on Module 1mvn verify
I can provide such a project as a zip if desired.
This happens because to generate the classpath The
JapiCmpMojo
is determining the set of dependencies viaRepositorySystem#resolveDependencies
insetUpClassPathUsingMavenProject()
. However this does not give you all dependencies that the module needs to compile, but only those dependencies that another module depending on that module would need, and since provided (and optional) dependencies are not transitive they are not put on the classpath.I couldn't find a nice way to solve this via the
RepositorySystem
API; the only alternative I could come up with is to use a customDependencySelector
that properly selects all dependencies that are required at compile time.This selector would be used like this:
I'm still prototyping such a selector, but it should be something along the lines of:
Alternatively, it might be possible to get the original set of dependencies from the Maven model, and create a CollectRequest for those dependencies instead (i.e., pretend to be the module).