I'm getting a java.lang.NoSuchMethodError
trying to invoke a Java method. As far as I can tell, the classpath is identical at compile-time and runtime-time so this error should not be occurring.
Repro steps:
Create 4 Maven projects:
- MyLibrary
- ExtensionPresent
- ExtensionMissing
- UserCode
Modules
ExtensionPresent
andExtensionMissing
export the same module name.ExtensionMissing
exports:
package dummy;
public class Extension {}
ExtensionPresent
exports:
package dummy;
public class Extension {
public static void present() {
System.out.println("Extension present!");
}
}
MyLibrary
declaresExtensionMissing
as a dependency.UserCode
declaresMyLibrary
as a dependency.UserCode.main()
invokesExtension.present()
. This triggers a compile-time error becauseExtensionMissing
does not contain this method.- Now for the interesting part... In the
UserCode
project, addExtensionPresent
as a dependency afterMyLibrary
. - I no longer get a compiler error (the method is now present at compile-time).
- When I try invoking
UserCode.main()
I get:
--- exec-maven-plugin:1.6.0:exec (default-cli) @ mavenproject3 ---
Exception in thread "main" java.lang.NoSuchMethodError: dummy.Extension.present()V
Is this a bug in my project configuration, Maven's implementation, or the JDK tools?
(On a side-note, I am doing this in an attempt to solve: Implementing a (compile-time) plugin architecture without split packages)
UPDATE: Here is an executable testcase: https://github.com/cowwoc/exec-maven-plugin-class-shadowing