Problems developing mojo tests with maven-plugin-testing-harness

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problems developing mojo tests with maven-plugin-testing-harness

ahardy42
Hi All

I'm writing a mojo and using maven-plugin-testing-harness.

Is there an issue with Java 8 streams or lambdas? When I include a method
on my mojo with some lambda functionality, I get this exception when it
tries to generate the mojo:

[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor
(default-descriptor) on project gem-config-maven-plugin: Execution
default-descriptor of goal
org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 62628
-> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute
goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor
(default-descriptor) on project gem-config-maven-plugin: Execution
default-descriptor of goal
org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 62628
        at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution
default-descriptor of goal
org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 62628
        at
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
        at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 21 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 62628
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at
org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scanDirectory(DefaultMojoAnnotationsScanner.java:204)
        at
org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:95)
        at
org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:125)
        at
org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:104)
        at
org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:108)
        at
org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:233)
        at
org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:92)
        at
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        ... 22 more
[ERROR]

This is the code:

    private String locateConfigurationJar() throws MojoExecutionException {
        Optional<Dependency> configDependency =
project.getDependencies().stream()
                .filter(this::testForConfigDependency)
                .findFirst();
        if (!configDependency.isPresent()) {
            throw new MojoExecutionException(String.format(
                    "Unable to find configuration dependency specified
[%s:%s]",
                    configDependencyGroupId, configDependencyArtifactId));
        }
        return configDependency.get().getSystemPath();
    }

    private boolean testForConfigDependency(Dependency dep) {
        return Objects.equals(configDependencyGroupId, dep.getGroupId()) &&
                Objects.equals(configDependencyArtifactId,
dep.getArtifactId());
    }


I also had some issues with the project dependency resolution because
maven-plugin-api and maven-plugin-testing-harness are pulling in the same
Plexus library, but under different guises -

org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.3 is actually the same
library as org.codehaus.plexus:plexus-io:jar:2.0.4


[INFO] +- org.apache.maven:maven-plugin-api:jar:3.5.0:compile
[INFO] |  +- org.apache.maven:maven-model:jar:3.5.0:compile
[INFO] |  +- org.apache.maven:maven-artifact:jar:3.5.0:compile
[INFO] |  \- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.3:compile
[INFO] |     +- javax.enterprise:cdi-api:jar:1.0:compile
[INFO] |     |  \- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |     \- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.3:compile
[INFO] +-
org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.5:provided
[INFO] +-
org.apache.maven.plugin-testing:maven-plugin-testing-harness:jar:3.3.0:test
[INFO] |  \- org.codehaus.plexus:plexus-archiver:jar:2.2:test
[INFO] |     +-
org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:test
[INFO] |     |  \- classworlds:classworlds:jar:1.1-alpha-2:test
[INFO] |     \- org.codehaus.plexus:plexus-io:jar:2.0.4:test

I am also badly held back by the lack of documentation or working
examples, after searching the net - where is the best place to look, or am
I already at the right place
https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/index.html?

While I'm asking, which is the best approach to setting up the mojo with
the testing harness - is MojoRule the way to go, or should I be able to
rely on AbstractMojoTestCase?

Best regards
Adam


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...