简体   繁体   English

如何使用Gradle将aar文件发布到Apache Archiva

[英]How to publish aar file to Apache Archiva with Gradle

I´m trying to publish the generated aar file of my android library to my Apache Archiva Maven server, but I haven´t manage to get it working yet because either the examples are outdated or they are for java and not for android 我试图将生成的我的android库的aar文件发布到我的Apache Archiva Maven服务器,但我还没设法让它工作,因为这些示例都已过时或者它们是针对java而不是针对android

After noticing that most methods of the gradle examples are deprecated, I found this new documentation: 在注意到gradle示例的大多数方法都已弃用之后,我发现了这个新文档:

Gradle Documentation Gradle文档

Which describes how to use the new API which seems to replace uploadArchives with publishing and so on.... 其中介绍了如何使用新的API,似乎将uploadArchives替换为发布等等....

So this is what I´ve got so far: 所以这就是我到目前为止所得到的:

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"


defaultConfig {
    applicationId "com.mycompany.mylibrary"
    minSdkVersion 9
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
lintOptions {
    abortOnError false
}

}


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

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

publishing {

publications {
    mavenJava(MavenPublication) {
        groupId 'com.android.mylibrary'
        artifactId 'MyLibrary'
        version '1.0.0'

        from components.java

        artifact sourceJar {
            classifier "sources"
        }
    }
}
repositories {
    maven {
        url "myurl"
        credentials{
            username "user"
            password "password"
        }
    }
}
}

The Gradle stuff is like the hell for me. Gradle的东西对我来说就像是地狱。 I don´t know what is right and what is wrong and some things seem to be changed without any hints that it isn´t supported anymore, which makes it quite difficult to solve these problems... 我不知道什么是正确的,什么是错的,有些事情似乎没有任何暗示,它不再受到支持,这使得解决这些问题变得非常困难......

How can I automatically upload the generated aar file to my Apache Archiva? 如何自动将生成的aar文件上传到我的Apache Archiva?

Solved it by myself 自己解决了

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"


repositories {
    mavenCentral()
}

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}


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

task sourceJar(type: Jar) {
   classifier "source"
}

publishing {
   publications {

       repositories.maven {
           url 'myurl/repositories/myrepo'
           credentials {
               username "user"
               password "password"
           }
       }

       maven(MavenPublication) {
           artifacts {
               groupId 'com.mycompany'
               artifactId 'mylibrary'
               version '1.0'
               artifact 'build/outputs/aar/app-release.aar'
           }
       }
   }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM