使用Allure2的@Step注解时出现NoSuchMethodError错误求助
NoSuchMethodError Issue Hey there, let's work through this frustrating Allure @Step error together. That NoSuchMethodError for StepsAspects.aspectOf() almost always ties back to dependency conflicts or issues with AspectJ weaving not working correctly. Here are actionable steps to fix it:
Verify AspectJ Version Compatibility
Allure 2.6.0 might have compatibility issues with older AspectJ versions like 1.9.1. Try upgrading youraspectj.versionto a newer release (e.g., 1.9.7 or later). Update the property in your pom.xml and re-run the tests—this often resolves method mismatch issues between Allure's aspects and the weaver.Fix Surefire Plugin's ArgLine Configuration
Double-check theargLinein your Maven Surefire plugin. Sometimes the path to the aspectjweaver jar isn't resolving correctly. You can try a more reliable way to reference the weaver:<argLine> -javaagent:"${maven.dependency.org.aspectj.aspectjweaver.jar.path}" </argLine>Also, ensure there are no extra spaces or typos in the path, and that the
aspectjweaverdependency is correctly declared in the Surefire plugin's dependencies section.Scan for Dependency Conflicts
Runmvn dependency:treein your project root to check for conflicting versions of Allure or AspectJ dependencies. Look for any transitive dependencies pulling in older versions ofallure-aspectsoraspectjrt—exclude those conflicting versions explicitly in your pom.xml. For example:<dependency> <groupId>problematic-group</groupId> <artifactId>problematic-artifact</artifactId> <exclusions> <exclusion> <groupId>io.qameta.allure</groupId> <artifactId>allure-aspects</artifactId> </exclusion> </exclusions> </dependency>Clean and Refresh Maven Dependencies
Corrupted or incomplete dependencies in your local Maven cache can cause weird class/method not found errors. Delete theio/qameta/allureandorg/aspectjfolders from your local repository (usually located at~/.m2/repository), then runmvn clean install -Uto re-download fresh copies of all dependencies.Check @Step Annotation Usage
Make sure your@Stepannotations are applied to public methods—Allure's AspectJ weaving won't pick up annotations on private or package-private methods. Also, avoid using@Stepon static methods unless you've configured AspectJ to handle static weaving (which requires extra setup).Compare with Your Working Project
Since you have another project with the same Allure version that works, runmvn dependency:treeon both projects and compare the outputs. Look for any differences in dependency versions, excluded artifacts, or plugin configurations—even a small discrepancy could be the root cause.Simplify and Update Plugin Configurations
You're right that you don't need both theallure-mavendependency and plugin. Stick with the plugin only, and try upgrading theallure-mavenplugin version to a newer release (e.g., 2.12.0) that's compatible with Allure 2.6.0. Sometimes outdated plugins can cause weaving issues.
内容的提问来源于stack exchange,提问作者Laucien

