Android Gradle将图书馆推送到本地/私人maven repo

Android Gradle将图书馆推送到本地/私人maven repo,android,android-studio,android-gradle-plugin,Android,Android Studio,Android Gradle Plugin,我刚刚从eclipse改为android studio。为了获得这些好处,gradle告诉我们,我正在尝试使用jForgs工件建立一个本地存储库。现在我面临的问题是,我想将我在Android Studio中编写的库推送/发布到工件中,这样我就可以在下一个Android应用程序项目中通过依赖项轻松导入它 文件夹结构如下所示: LibDeploy build.gradle gradle.properties -> app --> build --> libs

我刚刚从eclipse改为android studio。为了获得这些好处,gradle告诉我们,我正在尝试使用jForgs工件建立一个本地存储库。现在我面临的问题是,我想将我在Android Studio中编写的库推送/发布到工件中,这样我就可以在下一个Android应用程序项目中通过依赖项轻松导入它

文件夹结构如下所示:

LibDeploy
build.gradle
gradle.properties
-> app
    --> build
    --> libs
    --> src
        --> main
            --> java
    build.gradle
-> gradle   
    --> wrapper
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.0'
        classpath 'com.github.dcendents:android-maven-plugin:1.0'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.3'
    }
}

import java.text.SimpleDateFormat

def globalVersion = new Version(currentVersion)

// Define the artifacts coordinates
group = 'org.jfrog.example.android'
version = globalVersion
status = version.status

// Plugins
apply plugin: 'com.android.library'
apply plugin: 'artifactory'

// We need the patched maven plugin since 'install' task is overriden by 'installDebugTest', see: https://github.com/dcendents/android-maven-plugin
apply plugin: 'android-maven'

// Android
android {
    compileSdkVersion 21
    buildToolsVersion "21.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 21
    }
}

configurations {
    published
}

task sourceJar(type: Jar) {
    from android.sourceSets.main.java
    classifier "sources"
}

artifactoryPublish {
    dependsOn sourceJar
}

artifacts {
    published sourceJar
}

configure(install.repositories.mavenInstaller) {
    pom.project {
        licenses {
            license {
                name 'The Apache Software License, Version 2.0'
                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                distribution 'repo'
            }
        }
    }
}

artifactory {
    contextUrl = 'http://localhost:8080/artifactory'
    publish {
        repository {
            repoKey = 'libs-snapshot-local' //The Artifactory repository key to publish to
            username = artifactory_user //The publisher user name, property taken from gradle.properties
            password = artifactory_password //The publisher password, property taken from gradle.properties
        }
        defaults {
            publishConfigs('archives', 'published')
            properties = ['build.status': "$it.project.status".toString()]
            publishPom = true //Publish generated POM files to Artifactory (true by default)
            publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
        }
    }
    resolve {
        repository {
            repoKey = 'libs-release' //The Artifactory (preferably virtual) repository key to resolve from
            username = artifactory_user //Optional resolver user name (leave out to use anonymous resolution), property taken from gradle.properties
            password = artifactory_password //The resolver password, property taken from gradle.properties

        }
    }
}

repositories {
    jcenter()
}

// Our project dependencies
dependencies {
    compile 'joda-time:joda-time:2.3'

    // Backward compatibility for andoird <http://developer.android.com/tools/support-library/index.html>  
    //compile 'com.android.support:support-v4:19.1.+'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.1'
}

class Version {
    String thisVersion = 'default'
    String status = 'default'

    Version(String versionValue) {
        thisVersion = versionValue
        if (thisVersion.endsWith('-SNAPSHOT')) {
            status = 'integration'
        } else {
            status = 'release'
        }
    }

    String toString() {
        thisVersion
    }
}
应用程序文件夹中的my gradle.build如下所示:

LibDeploy
build.gradle
gradle.properties
-> app
    --> build
    --> libs
    --> src
        --> main
            --> java
    build.gradle
-> gradle   
    --> wrapper
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.0'
        classpath 'com.github.dcendents:android-maven-plugin:1.0'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.3'
    }
}

import java.text.SimpleDateFormat

def globalVersion = new Version(currentVersion)

// Define the artifacts coordinates
group = 'org.jfrog.example.android'
version = globalVersion
status = version.status

// Plugins
apply plugin: 'com.android.library'
apply plugin: 'artifactory'

// We need the patched maven plugin since 'install' task is overriden by 'installDebugTest', see: https://github.com/dcendents/android-maven-plugin
apply plugin: 'android-maven'

// Android
android {
    compileSdkVersion 21
    buildToolsVersion "21.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 21
    }
}

configurations {
    published
}

task sourceJar(type: Jar) {
    from android.sourceSets.main.java
    classifier "sources"
}

artifactoryPublish {
    dependsOn sourceJar
}

artifacts {
    published sourceJar
}

configure(install.repositories.mavenInstaller) {
    pom.project {
        licenses {
            license {
                name 'The Apache Software License, Version 2.0'
                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                distribution 'repo'
            }
        }
    }
}

artifactory {
    contextUrl = 'http://localhost:8080/artifactory'
    publish {
        repository {
            repoKey = 'libs-snapshot-local' //The Artifactory repository key to publish to
            username = artifactory_user //The publisher user name, property taken from gradle.properties
            password = artifactory_password //The publisher password, property taken from gradle.properties
        }
        defaults {
            publishConfigs('archives', 'published')
            properties = ['build.status': "$it.project.status".toString()]
            publishPom = true //Publish generated POM files to Artifactory (true by default)
            publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
        }
    }
    resolve {
        repository {
            repoKey = 'libs-release' //The Artifactory (preferably virtual) repository key to resolve from
            username = artifactory_user //Optional resolver user name (leave out to use anonymous resolution), property taken from gradle.properties
            password = artifactory_password //The resolver password, property taken from gradle.properties

        }
    }
}

repositories {
    jcenter()
}

// Our project dependencies
dependencies {
    compile 'joda-time:joda-time:2.3'

    // Backward compatibility for andoird <http://developer.android.com/tools/support-library/index.html>  
    //compile 'com.android.support:support-v4:19.1.+'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.1'
}

class Version {
    String thisVersion = 'default'
    String status = 'default'

    Version(String versionValue) {
        thisVersion = versionValue
        if (thisVersion.endsWith('-SNAPSHOT')) {
            status = 'integration'
        } else {
            status = 'release'
        }
    }

    String toString() {
        thisVersion
    }
}
我认为问题应该在build.gradle文件的这一行

task sourceJar(type: Jar) {
    from android.sourceSets.main.java
    classifier "sources"
}
有没有人对如何为我们的构建过程建立一个中心maven回购有很好的了解?
提前谢谢

我通过改变

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