{"record":{"id":"6294fad5e76c159e","repo":"Tencent/matrix","slug":"this-plugin-must-be-applied-after-java-or-com-a","errorCode":null,"errorMessage":"This plugin must be applied after \"java\" or \"com.android.library\" plugin","messagePattern":"This plugin must be applied after \"java\" or \"com\\.android\\.library\" plugin","errorType":"console","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/gradle/WeChatPublish.gradle","lineNumber":13,"sourceCode":"\ndef extensionClass\n\n// Detect supported plugin modules\nif (plugins.hasPlugin('com.android.library')) {\n    // Android library mode\n    extensionClass = WeChatAndroidLibraryPublishExtension.class\n} else if (plugins.hasPlugin('java')) {\n    // Java library mode\n    extensionClass = WeChatJavaLibraryPublishExtension.class\n} else {\n    // TODO: Support more languages\n    throw new GradleException('This plugin must be applied after \"java\" or \"com.android.library\" plugin')\n}\n\n// Register wechatPublish extension\nextensions.create('wechatPublish', extensionClass, project)\next.artifactId = name\n\nclass WeChatPublishExtension {\n\n    boolean isSnapshot = true\n    private String versionSuffix = ''\n    protected boolean printModules = false\n\n    boolean withJavadoc = true\n    boolean withSources = true\n    boolean withNativeSymbols = true\n    boolean withDependencies = true\n\n    boolean publishToBintray = false","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/gradle/WeChatPublish.gradle#L1-L31","documentation":"The WeChatPublish Gradle plugin inspects the plugins already applied to the project to decide which extension class to register (Android library, Android application, or plain Java). If neither 'java' nor 'com.android.library' (nor an Android application plugin) has been applied before this script runs, it cannot determine the publication type and throws a GradleException immediately at configuration time.","triggerScenarios":"Applying 'wechatPublish' (WeChatPublish.gradle) in a module whose build.gradle applies no 'java', 'java-library', 'com.android.library', or 'com.android.application' plugin, or applying it before the plugin block that adds them.","commonSituations":"Adding the publish script to a brand-new empty module, to an Android module where the android plugin is applied after the publish script line, or copying the script into a Kotlin/Multiplatform/agp-less project.","solutions":["Apply the appropriate plugin first: add plugins { id 'com.android.library' } (or 'java') in the module's build.gradle before 'apply from: ...WeChatPublish.gradle'","Reorder build script lines so 'apply from: gradle/WeChatPublish.gradle' comes after the android/java plugin application","If the module should not publish, remove the WeChatPublish apply line instead of keeping the plugin without a base plugin"],"exampleFix":"// before (module build.gradle)\napply from: rootProject.file('gradle/WeChatPublish.gradle')\napply plugin: 'com.android.library'\n\n// after\napply plugin: 'com.android.library'\napply from: rootProject.file('gradle/WeChatPublish.gradle')","handlingStrategy":"validation","validationCode":"// in module build.gradle, before applying WeChatPublish.gradle\nassert plugins.hasPlugin('com.android.library') || plugins.hasPlugin('java') : 'Apply java or com.android.library plugin before WeChatPublish'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always apply the base plugin ('java' or 'com.android.library') at the top of the module build file","Apply publish scripts last, after all plugin blocks","Centralize the apply order in a convention script so modules can't get it wrong"],"tags":["gradle","build-configuration","plugin-order"],"backgroundTag":"missing-dependency","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}