Executing Mojo Failed with `Java. Lang. Nosuchmethoderror` Org. Codehaus. Plexus. Util. Directoryscanner. setFilenameComparator

I have created 2 Mojos and recently decided to upgrade all my versions usign the maven version plugin.

Now, an executing one of my Mojos, I get this exception:

An API incompatibility was encountered while executing com.mycompany:spi2jars-maven-plugin:1.0-SNAPSHOT:spi2jars:

 java.lang.NoSuchMethodError: 'void org.codehaus.plexus.util.DirectoryScanner.setFilenameComparator(java.util.Comparator)

I know what this errors means, and I retrieve the full stacktrace by running with -X

Caused by: java.lang.NoSuchMethodError: 'void org.codehaus.plexus.util.DirectoryScanner.setFilenameComparator(java.util.Comparator)'
    at org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection.getResources (PlexusIoFileResourceCollection.java:250)
    at org.codehaus.plexus.archiver.AbstractArchiver$1.hasNext (AbstractArchiver.java:560)
    at org.codehaus.plexus.archiver.zip.AbstractZipArchiver.createArchiveMain (AbstractZipArchiver.java:221)
    at org.codehaus.plexus.archiver.zip.AbstractZipArchiver.execute (AbstractZipArchiver.java:199)
    at org.codehaus.plexus.archiver.AbstractArchiver.createArchive (AbstractArchiver.java:1042)
    at org.apache.maven.archiver.MavenArchiver.createArchive (MavenArchiver.java:676)
    at com.mycompany.Spi2Jars.createJarForLine (Spi2Jars.java:81)
    at com.mycompany.Spi2Jars.execute (Spi2Jars.java:47)

So it seems the MavenArchiver is at fault, or maybe a missing jar or incompatible versions.. But how do I check this?

[Update]

I found different versions of the underlying jars using

mvn dependency:tree -Dverbose 

For example:

\- org.apache.maven:maven-archiver:jar:3.5.0:compile
[INFO]    +- (org.apache.maven:maven-artifact:jar:3.0:compile - omitted for conflict with 3.6.0)
[INFO]    +- (org.apache.maven:maven-model:jar:3.0:compile - omitted for conflict with 3.6.3)
[INFO]    +- (org.apache.maven:maven-core:jar:3.0:compile - omitted for conflict with 3.6.3)
[INFO]    +- (org.apache.maven.shared:maven-shared-utils:jar:3.2.1:compile - omitted for duplicate)
[INFO]    +- commons-io:commons-io:jar:2.5:compile
[INFO]    +- org.codehaus.plexus:plexus-archiver:jar:4.2.0:compile
[INFO]    |  +- (org.codehaus.plexus:plexus-utils:jar:3.3.0:compile - omitted for conflict with 3.2.1)
[INFO]    |  +- org.codehaus.plexus:plexus-io:jar:3.2.0:compile
[INFO]    |  |  +- (org.codehaus.plexus:plexus-utils:jar:3.3.0:compile - omitted for conflict with 3.2.1)
[INFO]    |  |  \- (commons-io:commons-io:jar:2.6:compile - omitted for conflict with 2.5)
[INFO]    |  +- org.apache.commons:commons-compress:jar:1.19:compile
[INFO]    |  +- org.iq80.snappy:snappy:jar:0.4:compile
[INFO]    |  \- org.tukaani:xz:jar:1.8:runtime
[INFO]    +- (org.codehaus.plexus:plexus-utils:jar:3.3.0:compile - omitted for conflict with 3.2.1)
[INFO]    \- (org.codehaus.plexus:plexus-interpolation:jar:1.25:compile - omitted for conflict with 1.11)

It would be so awesome if the most recent maven plugins played nice together... It seems they don't. How do I resolve this nicely?

1 Answer

I had a similar issue (same error message).

I could solve this isse by declaring the following direct dependency in our custom plugin:

    <dependency>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-utils</artifactId>
        <version>3.3.0</version>
    </dependency>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest