Resolving 'Plugin with id "maven" not found' in Gradle
When upgrading to Gradle 7.x, many developers encounter the error "Plugin with id 'maven' not found." This error occurs because the legacy Maven plugin has been removed from Gradle's standard distribution. This article explains why this happens and provides practical solutions.
Why does this error occur?
The maven
plugin was officially removed in Gradle 7.0 as part of the framework's modernization efforts. According to the official Gradle upgrade documentation, this legacy plugin has been replaced by the more modern maven-publish
plugin.
The problematic code typically looks like this:
subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven' // This line causes the error in Gradle 7+
}
Solution: Use maven-publish plugin
The recommended solution is to replace the legacy maven
plugin with the newer maven-publish
plugin:
subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven-publish' // Modern replacement
}
The maven-publish
plugin provides improved functionality and follows Gradle's modern publishing model. It offers better support for:
- Publishing to Maven repositories
- Generating POM files with proper metadata
- Configuring publications with multiple components
- Customizing publishing tasks
Alternative approaches
Downgrading Gradle version
While not recommended for new projects, you can downgrade to Gradle 6.x if you need to maintain compatibility with existing builds:
WARNING
Downgrading is a temporary solution and may cause compatibility issues with newer plugins and dependencies.
To downgrade in Android Studio:
- Go to
File
→Project Structure
- Set Android Gradle Plugin Version to 4.2.2
- Set Gradle Version to 6.7.1
Using Gradle Wrapper with older version
You can configure the Gradle Wrapper to use a specific version:
./gradlew wrapper --gradle-version 6.9
Then use the wrapper for all tasks:
./gradlew clean build
Complete maven-publish example
Here's a complete example of using the modern maven-publish
plugin:
plugins {
id 'java'
id 'maven-publish'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
// Add additional configuration as needed
}
}
repositories {
maven {
// Configure your repository here
url = version.endsWith('SNAPSHOT') ?
snapshotsRepoUrl : releasesRepoUrl
credentials {
username = project.repoUser
password = project.repoPassword
}
}
}
}
Migration considerations
When migrating from the legacy maven
plugin to maven-publish
, be aware of these changes:
INFO
- Task names have changed (e.g.,
uploadArchives
becomespublish
) - Configuration syntax is different
- The new plugin provides better control over publication metadata
Conclusion
The "Plugin with id 'maven' not found" error is a straightforward compatibility issue when upgrading to Gradle 7+. The most sustainable solution is to migrate to the maven-publish
plugin, which offers improved functionality and follows Gradle's modern conventions. While downgrading Gradle versions can work as a temporary fix, it's recommended to update your build scripts for long-term compatibility.
For more details, refer to the official Gradle upgrading guide.