Gradle构建Axion Release Plugin应用失败报错求助
Hey there, let's figure out why you're hitting that Cannot invoke method version() on null object error right after applying the Axion Release Plugin, even without using its features yet. Here are the most likely causes and fixes:
1. Plugin Application Order is Off
Android projects have specific plugin initialization dependencies, and Axion needs to be applied before the Android library plugin in your module's build.gradle. If you applied Android first, the Android plugin tries to access the project's version property before Axion has had a chance to set up its version management context, leading to the null error.
Fix:
Adjust your plugins block to this order:
plugins { id 'pl.allegro.tech.build.axion-release' id 'com.android.library' }
2. Missing Minimal Axion Configuration
Even if you don't want to use all of Axion's features yet, it needs basic setup to initialize its version extension properly. Axion relies on your SCM (like Git) to derive version info, so skipping this setup leaves the version context null.
Fix:
Add a minimal Axion configuration block to your build.gradle to let it initialize correctly:
version { scmVersion { tagPrefix = "v" // Match your Git tag convention (e.g., v1.0.0) } }
3. Android versionName is Dependent on Uninitialized project.version
If your Android default config uses project.version directly for versionName, the Android plugin will try to read this value before Axion has populated it.
Fix:
Reference Axion's initialized version value instead:
android { defaultConfig { versionName version.scmVersion.version } }
4. Gradle Version Compatibility Issue
Axion has strict Gradle version requirements (e.g., newer versions need Gradle 7.0+). If your project uses an older Gradle version, the plugin might fail to initialize its internal components, causing the null error.
Fix:
Check your project's Gradle version against the Axion plugin's compatibility requirements, and upgrade Gradle if needed.
Quick Validation Steps
- Double-check the plugin order in your
build.gradle - Add the minimal SCM configuration for Axion
- Replace any direct
project.versionreferences in your Android config with Axion's version property - Verify your Gradle version matches the plugin's requirements
内容的提问来源于stack exchange,提问作者Leonardo Oliveira

