2015-04-30 55 views
1

我一直在嘗試上傳一個項目到Maven存儲庫失敗。這裏是我的項目結構:Android多模塊與味道到Maven存儲庫

_root 
    |_ lib1 (aar) 
    |_ lib2 (aar) 
    |_ javalib (jar) 
  • LIB1取決於LIB2
  • LIB2取決於javalib
  • LIB1和LIB2有兩種口味(INTG和生產線)

問題是什麼時候啓動uploadArchives任務我沒有創建pom.xml。 這似乎是由於我的口味(當我刪除口味,它工作正常),我不知道如何解決這個問題。 我真的需要風味工作...任何幫助是值得歡迎;)

這裏是我的build.gradle文件:

根:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.1.0' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

ext.versionName = "$System.properties.version" 

configure(subprojects) { 

    apply plugin: 'maven' 

    group = 'com.test.build' 
    version = project.versionName 

    uploadArchives { 
     repositories { 
      mavenDeployer { 
       repository(url: "http://localhost:8081/content/repositories/test/") { 
        authentication(userName: "admin", password: "admin123") 
       } 
      } 
     } 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

LIB1:

apply plugin: 'com.android.library' 

android { 
    publishNonDefault true 

    compileSdkVersion 22 
    buildToolsVersion "22.0.1" 

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

    productFlavors { 
     prod{} 
     intg{} 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    intgCompile project(path: ':lib2', configuration: 'intgRelease') 
    prodCompile project(path: ':lib2', configuration: 'prodRelease') 
} 

lib2:

apply plugin: 'com.android.library' 

android { 
    publishNonDefault true 

    compileSdkVersion 22 
    buildToolsVersion "22.0.1" 

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

    productFlavors { 
     prod{} 
     intg{} 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile project(path: ':javalib') 
} 

javalib:

apply plugin: 'java' 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
} 

回答

4

我終於找到了答案,我的問題: 這是不可能的,但有可能做到這一點第一天: 看到文檔有關: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

我通過這個問題,這個解決方案去:

// default publication is production which will be published without env name 
    publishNonDefault true 
    defaultPublishConfig "productionRelease" 
    if (android.productFlavors.size() > 0) { 
     android.libraryVariants.all { variant -> 
      // Publish a main artifact, otherwise the maven pom is not generated 
      if (android.publishNonDefault && variant.name == android.defaultPublishConfig) { 
       def bundleTask = tasks["bundle${name.capitalize()}"] 
       artifacts { 
        archives(bundleTask.archivePath) { 
         classifier null 
         builtBy bundleTask 
        } 
       } 
      } 
     } 
    } 

我不太滿意,但它會爲現在做的工作...