diffplug / spotless

Keep your code spotless
Apache License 2.0
4.43k stars 449 forks source link

Maven can't locate this plugin due to "org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException: No plugin found for prefix 'spotless'" #520

Open matts19 opened 4 years ago

matts19 commented 4 years ago

When try to run "mvn -s settings.xml spotless:check", it can't locate this plugin due to "org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException: No plugin found for prefix 'spotless'"

I even entered the plugin group info in settings.xml:
<pluginGroups>
  <pluginGroup>com.diffplug.spotless</pluginGroup>
</pluginGroups>

But maven refuses to find this plugin via prefix. Full naming works though (com.diffplug.spotless:spotless-maven-plugin:check).

For the prefix to work my understanding is that the plugin should provide prefix info in its maven-metadata.xml at the group level. But this plugin does not come with such meta data file. It only has maven-metadata.xml at the artifact level for each artifact version. That is, I could not find maven-metadata.xml which content like this:

<metadata>
  <plugins>
    <plugin>
      <name>Some Awesome Maven Plugin</name>
      <prefix>somePrefix</prefix>
      <artifactId>some-maven-plugin</artifactId>
    </plugin>
  </plugins>
</metadata>

- [ ] gradle or maven version

Maven 3.5.0

- [ ] spotless version

1.27.0 but I tried many other versions

- [ ] operating system and version

Ubuntu Xenial

- [ ] copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible

It's very simple.

<plugin>
    <groupId>com.diffplug.spotless</groupId>
    <artifactId>spotless-maven-plugin</artifactId>
    <version>1.21.0</version>
    <configuration>
        <java>
            <removeUnusedImports/>
        </java>
    </configuration>
</plugin>

- [ ] copy-paste the full content of any console errors 

[DEBUG] Resolving plugin prefix spotless from [com.diffplug.spotless, org.apache.maven.plugins, org.codehaus.mojo]
[DEBUG] Using mirror repo (http://scctools.dt.vmware.com:8081/artifactory/repo) for plexus-snapshots (https://oss.sonatype.org/content/repositories/plexus-snapshots).
[DEBUG] Using mirror repo (http://scctools.dt.vmware.com:8081/artifactory/repo) for apache.snapshots (http://repository.apache.org/snapshots).
[DEBUG] Using mirror repo (http://scctools.dt.vmware.com:8081/artifactory/repo) for codehaus.org (http://snapshots.repository.codehaus.org).
[DEBUG] Could not find metadata com.diffplug.spotless/maven-metadata.xml in local (/home/jenkins/.m2/repository)
[DEBUG] Could not find metadata org.apache.maven.plugins/maven-metadata.xml in local (/home/jenkins/.m2/repository)
[DEBUG] Could not find metadata org.codehaus.mojo/maven-metadata.xml in local (/home/jenkins/.m2/repository)
[DEBUG] Using transporter WagonTransporter with priority -1.0 for http://scctools.dt.vmware.com:8081/artifactory/repo
[DEBUG] Using transporter WagonTransporter with priority -1.0 for http://scctools.dt.vmware.com:8081/artifactory/repo
[DEBUG] Using transporter WagonTransporter with priority -1.0 for http://scctools.dt.vmware.com:8081/artifactory/repo
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://scctools.dt.vmware.com:8081/artifactory/repo
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://scctools.dt.vmware.com:8081/artifactory/repo
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://scctools.dt.vmware.com:8081/artifactory/repo
Downloading: http://scctools.dt.vmware.com:8081/artifactory/repo/org/apache/maven/plugins/maven-metadata.xml
Downloading: http://scctools.dt.vmware.com:8081/artifactory/repo/org/codehaus/mojo/maven-metadata.xml
Downloading: http://scctools.dt.vmware.com:8081/artifactory/repo/com/diffplug/spotless/maven-metadata.xml
[DEBUG] Writing tracking file /home/jenkins/.m2/repository/com/diffplug/spotless/resolver-status.properties

<snipped....>

[DEBUG] Could not find metadata com.diffplug.spotless/maven-metadata.xml in repo (http://scctools.dt.vmware.com:8081/artifactory/repo)
[DEBUG] Could not find metadata com.diffplug.spotless/maven-metadata.xml in local (/home/jenkins/.m2/repository)
[DEBUG] Skipped remote request for com.diffplug.spotless/maven-metadata.xml, already updated during this session.
[DEBUG] Failure to find com.diffplug.spotless/maven-metadata.xml in http://scctools.dt.vmware.com:8081/artifactory/repo was cached in the local repository, resolution will not be reattempted until the update interval of repo has elapsed or updates are forced
[DEBUG] Could not find metadata org.apache.maven.plugins/maven-metadata.xml in local (/home/jenkins/.m2/repository)
[DEBUG] Could not find metadata org.codehaus.mojo/maven-metadata.xml in local (/home/jenkins/.m2/repository)
Shanky2304 commented 4 years ago

I have the same issue. It'll be much more handy if people can use the shorter version for this plugin otherwise it will just fizzle out as one of those "recommendations"

nedtwigg commented 4 years ago

This might be a dumb question, but I'm not great with maven. At the very top of our plugin-maven readme, we've got a little plugin block to copy, and it looks like you copied it exactly right. We also have an example command line mvn spotless:check. I do a little integration testing for each release to confirm that it is still working, and it is, for me.

I don't understand how having a <pluginGroups> in your settings.xml comes into it at all. I read these maven docs which reference it, but I still don't get it.

Regardless of whether I understand the problem or not, we're happy to take a PR to fix/improve it. Here is our POM template:

https://github.com/diffplug/spotless/blob/e870e78999887595d8480c699c4ef71c9e974b32/plugin-maven/src/test/resources/pom-build.xml.mustache

And here is how we populate and run it:

https://github.com/diffplug/spotless/blob/e870e78999887595d8480c699c4ef71c9e974b32/plugin-maven/build.gradle#L139-L180

I'm happy to help with any gradle integration issues, but I don't know anything about the maven part.

nedtwigg commented 4 years ago

Closing due to inactivity and inability to replicate. Happy to reopen with an open source repo that demonstrates the issue.

vlaw commented 1 year ago

I have the same issue.

$ mvn -X spotless:check
...
[DEBUG] Could not find metadata com.diffplug.spotless/maven-metadata.xml in central (https://repo.maven.apache.org/maven2)
......
......
[ERROR] No plugin found for prefix 'spotless' in the current project and in the plugin groups [com.diffplug.spotless, com.github.spotbugs, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/luowentao/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]

I'm not familiar with building a maven plugin neither. But I do find something, I guess. There is NO maven-metadata.xml under https://repo.maven.apache.org/maven2/com/diffplug/spotless/.

As a contrast, there are two other pluginGroups , which have maven-metadata.xml in centra repo.

<metadata>
<plugins>
  <plugin>
    <name>SpotBugs Maven Plugin</name>
    <prefix>spotbugs</prefix>      <!-- HERE -->
    <artifactId>spotbugs-maven-plugin</artifactId>
  </plugin>
</plugins>
</metadata>

So, maybe there is something go wrong during DEPLOY phrase, or maybe maven-publish error? I'm not quit sure, hope this will give some clue.

glucazeau commented 2 months ago

👋 It is unfortunately still an issue.

As @vlaw said the repository is missing maven-metadata file (another example for sonar:sonar plugin : maven-metadata.xml)

According to the documentation, this file at group level should be automatically uploaded when using "maven-plugin" as packaging type. I couldn't find where and if this packaging type is specified somewhere in the Gradle build configuration of the plugin.

Furthermore, it says here that the Gradle "maven-publish" plugin seems to ignore the packaging type. I don't know if it's still the case, but I would suppose that this plugin is used for traditional Maven projects, and that most of the Maven plugins are built and published with Maven itself.

I hope this can help, it would be really nice to be able to simply call mvn spotless:check (on a global GitHub workflow for instance)

a-t-0 commented 1 month ago

For anyone searching to resolve the same No plugin found for prefix 'spotless' error, here is a solution (that uses Maven).