1

I am getting this error: [ERROR] Plugin org.apache.maven.plugins:maven-surefire-plugin:2.12.4 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-surefire-plugin:jar:2.12.4 in nexus-xyz-plugin

I tried to run maven with dependecy:tree, but I can't see surefire, and I dont know why it is looking for this specific version 2.12.4 which is not specified in my pom!

Even the surefire plugin is not defined in my pom, but I have the assembly plugin not sure if assembely is dependent on surefire

Note that I only get the error when running mvn package, however when running mvn compile the build succeeds

  • Does this answer your question? [How can you display the Maven dependency tree for the \*plugins\* in your project?](https://stackoverflow.com/questions/7074590/how-can-you-display-the-maven-dependency-tree-for-the-plugins-in-your-project) – slindenau May 19 '22 at 15:13
  • Hello, if it doesn't answer it certianly helps, I ran the command `mvn dependecy:resolve-plugins` and I can see in the plugins resolved the mvn surefire plugin listed, doesn't that mean that the surefire plugin is downloaded normally? @slindenau – ethicalhacker May 20 '22 at 06:59
  • If it is listed in the output the plugin must be mentioned somewhere in your pom yes. Are you using a parent pom? You can try `mvn help:effective-pom` to show your complete pom.xml file. If the error is that you can't download surefire, make sure to check you have a `` element in your pom that references [maven central](https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin/2.12.4). Finally you can try to run your maven build with the `-X` option to show debug logging. – slindenau May 20 '22 at 12:23

1 Answers1

2

Version 2.12.4 of the maven-surefire-plugin is always added to the pom by maven version 3.x unless you depend on a specific other version.

Maven has a so called super pom that you get for free, but that doesn't list surefire: https://maven.apache.org/ref/3.8.5/maven-model-builder/super-pom.html

However it is added to the pom, i've checked this with maven 3.3.9. You can verify this by running mvn help:effective-pom.

Reference with the same problem: No surefire plugin in my pom - How does it show surefire output?

These plugin versions are part of the default bindings for lifecycle executions, in this case of the test phase. So these plugins are always included if not specified.

See for reference:

Normally this plugin should be available in maven central, check if you have a <pluginRepository> in your (effective) pom that references https://repo1.maven.org/maven2/

Some other things you can check:

  • Open the file .m2\repository\org\apache\maven\plugins\maven-surefire-plugin\2.12.4\maven-surefire-plugin-2.12.4.jar.lastUpdated and check the error message for each repository. Check why it can't reach maven central; is it missing from the list or giving an error? This might be a company firewall/policy issue perhaps? Or is it giving an error on HTTPS/TLS protocol level?
  • Check if you can add maven central to your repositories list if it's missing somehow (should be included by default). Check if it's HTTP or HTTPS, only secure is supported now.
  • Run your maven command with -X for debug mode to investigate further

An alternative is to add the latest version of surefire to your project that is available in your plugin-repository, and perhaps disable it if you're not executing unit tests.

See Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.

slindenau
  • 1,091
  • 2
  • 11
  • 18
  • hello thank you for the detailed explanation, yes you're right apparently the surefire plugin is defined by default and that is why it was trying to get this plugin version 2.12.4. I am not using maven central, I am using an internal private repo which doesn't have this version. – ethicalhacker May 25 '22 at 07:35