使用附加在artifactory repo上的javadocs发布.aar文件

时间:2015-09-01 19:13:45

标签: android maven gradle artifactory aar

我试图通过神器gradle puglin将带有javadoc文件的AAR发布到我的maven repo。

aar文件正在上传成功,但我不是javadoc。我可以使用哪个脚本上传我的javadoc?。

这是我的build.gradle代码

apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

def packageName = 'br.com.lexsis.libtest'
def libraryVersion = '0.0.1-SNAPSHOT'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
}

publishing {
    publications {
        aar(MavenPublication) {
            groupId packageName
            version = libraryVersion
            artifactId project.getName()

            // Tell maven to prepare the generated "*.aar" file for publishing
            artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")

            pom.withXml {
                def dependencies = asNode().appendNode('dependencies')
                configurations.getByName("_releaseCompile").getResolvedConfiguration().getFirstLevelModuleDependencies().each {
                    def dependency = dependencies.appendNode('dependency')
                    dependency.appendNode('groupId', it.moduleGroup)
                    dependency.appendNode('artifactId', it.moduleName)
                    dependency.appendNode('version', it.moduleVersion)
                }
            }
        }
    }
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            // The Artifactory repository key to publish to
            repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'

            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
        defaults {
            // Tell the Artifactory Plugin which artifacts should be published to Artifactory.
            publications('aar')
            publishArtifacts = true

            // Properties to be attached to the published artifacts.
            properties = ['qa.level': 'basic', 'dev.team': 'core']
            // Publish generated POM files to Artifactory (true by default)
            publishPom = true
        }
    }
}

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}

2 个答案:

答案 0 :(得分:8)

您的出版物仅包含aar文件:

artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")

添加另一个工件 - androidJavadocsJar任务的输出:

artifact androidJavadocsJar

如果需要,重复源jar。

答案 1 :(得分:6)

这适合我。

apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

def packageName = 'br.com.lexsis.libtest'
def libraryVersion = '0.0.1-SNAPSHOT'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.0"

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   compile 'com.android.support:appcompat-v7:23.0.0'
}

publishing {
publications {
    aar(MavenPublication) {
        groupId packageName
        version = libraryVersion
        artifactId project.getName()

        // Tell maven to prepare the generated "*.aar" file for publishing
        artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
        artifact androidJavadocsJar

        pom.withXml {
            def dependencies = asNode().appendNode('dependencies')
            configurations.getByName("_releaseCompile").getResolvedConfiguration().getFirstLevelModuleDependencies().each {
                def dependency = dependencies.appendNode('dependency')
                dependency.appendNode('groupId', it.moduleGroup)
                dependency.appendNode('artifactId', it.moduleName)
                dependency.appendNode('version', it.moduleVersion)
            }
        }
    }
}
}

artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
    repository {
        // The Artifactory repository key to publish to
        repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'

        username = "${artifactory_user}"
        password = "${artifactory_password}"
    }
    defaults {
        // Tell the Artifactory Plugin which artifacts should be published to Artifactory.
        publications('aar')
        publishArtifacts = true

        // Properties to be attached to the published artifacts.
        properties = ['qa.level': 'basic', 'dev.team': 'core']
        // Publish generated POM files to Artifactory (true by default)
        publishPom = true
    }
}
}

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath +=    project.files(android.getBootClasspath().join(File.pathSeparator))
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}