Specifying the expanded file name for an AAR artifact in an Android library project

I am trying to set up an Android library project to deploy multiple artifacts in a locally hosted Maven repository. I got far enough that both artifacts had their own POM, and it deploys correctly in the repo, with the following script:

android {
    // Publish both debug and release
    publishNonDefault true
}

uploadArchives {
    repositories.mavenDeployer {
        def majorVersion = 1
        def minorVersion = 1
        def buildVersion = project.properties.get('RELEASE', '0').toInteger()

        addFilter('release') { artifact, file ->
            file.name.contains('release')
        }

        addFilter('debug') { artifact, file ->
            file.name.contains('debug')
        }

        activePomFilters.each { filter ->
            pom(filter.name) {
                groupId = 'com.redacted'
                artifactId = 'redacted'
                packaging = 'aar'
                version = "${majorVersion}.${minorVersion}.${buildVersion}"

                if (!project.hasProperty('RELEASE')) {
                    version += "-SNAPSHOT"
                }

                if (filter.name == 'debug') {
                    artifactId += '-debug'
                }
            }
        }
    }
}

Expected Delivery:

com/
    redacted/
        redacted/
            1.1.0-SNAPSHOT/
        redacted-debug/
            1.1.0-SNAPSHOT/

This happens as expected, but seems to publish artifacts with an additional suffix (which violates dependency detection), and I cannot figure out where it comes from or how to change it. I see:

com/redacted/redacted/1.1.0-SNAPSHOT/
    redacted-1.1.0-20150717.213849-1-release.aar
    redacted-1.1.0-20150717.213849-1-release.aar.md5
    redacted-1.1.0-20150717.213849-1-release.aar.sha1
    redacted-1.1.0-20150717.213849-1.pom
    redacted-1.1.0-20150717.213849-1.pom.md5
    redacted-1.1.0-20150717.213849-1.pom.sha1

For some reason, it adds the date, as well as the -release suffix, only to AAR-related files, but not to POM files. If I manually rename these files, everything will work as expected. For example, this is what I expect for output:

com/redacted/redacted/1.1.0-SNAPSHOT/
    redacted-1.1.0-20150717.213849-1.aar
    redacted-1.1.0-20150717.213849-1.aar.md5
    redacted-1.1.0-20150717.213849-1.aar.sha1
    redacted-1.1.0-20150717.213849-1.pom
    redacted-1.1.0-20150717.213849-1.pom.md5
    redacted-1.1.0-20150717.213849-1.pom.sha1

?

+4
1

, , - ( ):

: Maven ( ). , maven. , .

. : http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

release debug, , - , , , . <artifact> build/ivy.xml, Maven, .

. , .

, . null . , (= + ), . , :

class UnclassifiedPublishArtifact implements PublishArtifact {

    private PublishArtifact delegatee;
    private boolean isDebugArtifact;

    UnclassifiedPublishArtifact(PublishArtifact delegatee, isDebugArtifact) {
        this.delegatee = delegatee
        this.isDebugArtifact = isDebugArtifact
    }

    @Override
    String getName() {
        return delegatee.name + (isDebugArtifact ? '-debug' : '')
    }

    @Override
    String getExtension() {
        return delegatee.extension
    }

    @Override
    String getType() {
        return delegatee.type
    }

    @Override
    String getClassifier() {
        return null
    }

    @Override
    File getFile() {
        return delegatee.file
    }

    @Override
    Date getDate() {
        return delegatee.date
    }

    @Override
    TaskDependency getBuildDependencies() {
        return delegatee.buildDependencies
    }
}

project.afterEvaluate {
    configurations.each { configuration ->
        def artifacts = configuration.artifacts
        if (!artifacts.isEmpty()) {
            def unclassifiedArtifacts = []
            unclassifiedArtifacts.addAll(artifacts.collect { classifiedArtifact ->
                new UnclassifiedPublishArtifact(classifiedArtifact, classifiedArtifact.classifier == 'debug')
            })
            artifacts.clear()
            artifacts.addAll(unclassifiedArtifacts)
        }
    }
}

, , , .

+3

Source: https://habr.com/ru/post/1598448/


All Articles