【问题标题】:Maven Surefire Plugin version confusionMaven Surefire 插件版本混乱
【发布时间】:2026-02-07 12:40:01
【问题描述】:

我是这样添加插件的:

    <maven.surefire.version>3.0.0-M5</maven.surefire.version>

    [...]

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.version}</version>
        <configuration>
          <parallel>methods</parallel>
          <useUnlimitedThreads>true</useUnlimitedThreads>
        </configuration>
      </plugin>

……一切顺利。

我将版本更改为 2.22.2 并收到错误:Plugin 'org.apache.maven.plugins:maven-surefire-plugin:2.22.2' not found

但是,当我在 IntelliJ 中进行工件搜索时,它确实找到了那个版本。好的,我将更改恢复到原来的版本。

现在,当我运行 mvn test 时,以下内容引起了我的注意:

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ regression-tests ---

为什么不使用 3.0.0-M5? 2.12.4 来自哪里?我在我的 pom.xml 中搜索了“surefire”,但除了上面显示的内容之外,没有出现其他命中。

查看 IntelliJ 的 Preferences,我发现正在使用的 repo 是 https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/,所有提到的版本都在那里。

有人可以向我解释发生了什么吗?为什么找不到 2.22.2?为什么在 pom.xml 中显示使用的是 2.12.4 而 3.0.0-M5?

为了完整起见,这是我的 mvn:

❯ mvn --version
Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /opt/homebrew/Cellar/maven/3.8.2/libexec
Java version: 1.8.0_292, vendor: Azul Systems, Inc., runtime: /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "11.5.2", arch: "aarch64", family: "mac"

【问题讨论】:

    标签: maven intellij-idea maven-surefire-plugin


    【解决方案1】:

    好的,我将更改恢复到原来的版本。

    更改 pom.xml 文件后,在 Maven 工具窗口中调用 Reload 操作。

    您可以在 Maven 工具窗口中查看使用的插件版本:

    您还可以在 IDE 中使用 Show Effective POM 操作来查看此 Maven 项目中使用的所有实际依赖项、插件及其版本:

    【讨论】:

    • 在 Maven 工具窗口中,它显示 2.12.4。所以,那里没有什么新鲜事。 Show Effective POM 对我来说是新的,它仍然向我展示了 2.12.4。但是,我注意到 Surefire 2.22.2 的整个插件部分都消失了。所以,正因为如此,我发现了问题所在。此 pom 文件使用 Profiles,而 Surefire 仅在其中一个 Profiles 中列出。因此,当该 Profile 不活动时,它实际上(双关语)意味着 Maven 加载了它想要的任何内容。所以我将插件复制到其他配置文件,现在它可以工作了。谢谢。