Tencent/matrix · error · GradleException

Invalid version

Error message

Invalid version: ${fullVersion}

What it means

checkVersion() validates the fullVersion string (assembled from version + optional qualifiers) against the regex /\d+\.\d+(?:\.\d+)?(?:\.\d+)?(?:-[\w-]+)?/. For non-snapshot versions a mismatch throws a GradleException; for snapshot versions it only prints a warning to stderr so CI snapshot publishing can continue.

Solutions

  1. Fix project.version to match the required format, e.g. '1.2.3' or '1.2.3-beta-1' (use '-' before the qualifier)
  2. Strip a leading 'v' or other decoration from versions derived from git tags/env vars before publishing
  3. If the version is intentionally non-standard and this is a snapshot build, publish with isSnapshot so it only warns
  4. Temporarily relax the regex in WeChatPublish.gradle if your org needs a different scheme (coordinate with consumers since it encodes publish coordinates)

Example fix

// before
version = 'v1.4.0'

// after
version = '1.4.0'
Defensive patterns

Strategy: validation

Validate before calling

// shell/groovy pre-check before invoking publish
def v = project.version as String
assert v ==~ /\d+\.\d+(?:\.\d+)?(?:\.\d+)?(?:-[\w-]+)?/ : "Version '$v' does not match required format"

Prevention

When it happens

Trigger: project.version set to something like '1.0-abc!' , 'v2.3', '2', '1.0.RC1' (dot separators in qualifier), or any string not matching digits.digits[.digits][.digits][-qualifier] while isSnapshot is false.

Common situations: Setting version from an environment variable or git tag containing a leading 'v', using '.' instead of '-' in pre-release qualifiers (1.0.beta.1), or accidentally leaving the version empty.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/de800e29461409c4. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/gradle/WeChatPublish.gradle:159

        checkVersion()

        if (!usedDefaultIsSnapshot) {
            System.err.println 'isSnapshot should be avoided in build scripts.'
        }

        if (isSnapshot) {
            // Bintray does not allow SNAPSHOT publish
            publishToBintray = false
        }

        project.ext.fullVersion = fullVersion
    }

    private void checkVersion() {
        if (!(fullVersion ==~ /\d+\.\d+(?:\.\d+)?(?:\.\d+)?(?:-[\w-]+)?/)) {
            def message = "Invalid version: ${fullVersion}"
            if (!isSnapshot)
                throw new GradleException(message)
            System.err.println(message)
        }
    }

    final protected String getPublicationName() {
        String result = ""
        artifactId.split("[-_]").each { result += it.capitalize() }
        return uncapitalize(result)
    }

    protected void mountAdditionalLogic(project) {}

    protected void emitPublicationDSL(Project project) {}

    private void emitRepositoryDSL(Project project) {
        mavenPublishClosures.each { cl ->
            project.publishing.repositories {
                maven {

View on GitHub (pinned to 3b8293bd65)