2014-11-26 9 views
14

Próbuję przekazać wiele artefaktów na projekcie w/maven Gradle plugin:Jak przesłać wiele android archiwów (po jednym dla każdego smaku)

http://www.gradle.org/docs/current/userguide/maven_plugin.html

53.6.4.1. Multiple artifacts per project 

Maven can only deal with one artifact per project. This is reflected in the structure of the Maven POM. We think there are many situations where it makes sense to have more than one artifact per project. In such a case you need to generate multiple POMs. In such a case you have to explicitly declare each artifact you want to publish to a Maven repository. The MavenDeployer and the MavenInstaller both provide an API for this: 

Example 53.9. Generation of multiple poms 

build.gradle 
uploadArchives { 
    repositories { 
     mavenDeployer { 
      repository(url: "file://localhost/tmp/myRepo/") 
      addFilter('api') {artifact, file -> 
       artifact.name == 'api' 
      } 
      addFilter('service') {artifact, file -> 
       artifact.name == 'service' 
      } 
      pom('api').version = 'mySpecialMavenVersion' 
     } 
    } 
} 
You need to declare a filter for each artifact you want to publish. This filter defines a boolean expression for which Gradle artifact it accepts. Each filter has a POM associated with it which you can configure. To learn more about this have a look at PomFilterContainer and its associated classes. 

Naprawdę to, co staram się robić to wgrywanie różnych archiwów dla różnych smaków mojej kompilacji.

Oto moje projekty build.gradle plik:

apply plugin: 'com.android.library' 
apply plugin: 'maven' 

group 'com.test' 
version '0.0.1' 

android { 
    compileSdkVersion 19 
    buildToolsVersion "21.1.1" 

    defaultConfig { 
     minSdkVersion 14 
     targetSdkVersion 19 
    } 

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

    lintOptions { 
     abortOnError false 
    } 

    productFlavors { 
     flavor1 { } 
     flavor2 { } 
    } 

    packagingOptions { 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/NOTICE.txt' 
    } 
} 

uploadArchives { 
    repositories { 
     mavenDeployer { 
      repository(url: "file://${System.properties['user.home']}/.m2/repository") 

      addFilter('debugFlavor1') { artifact, file -> 
       artifact.name.contains("debugFlavor1") 
      } 
      addFilter('releaseFlavor1') { artifact, file -> 
       artifact.name.contains("releaseFlavor1") 
      } 
      addFilter('debugFlavor2') { artifact, file -> 
       artifact.name.contains("debugFlavor2") 
      } 
      addFilter('releaseFlavor2') { artifact, file -> 
       artifact.name.contains("releaseFlavor2") 
      } 

      pom('debug').artifactId = ${artifactId} + "-" ${flavor} + "-debug" 
      pom('release').artifactId = ${artifactId} + "-" ${flavor} 
     } 
    } 
} 


dependencies { 
    compile 'com.android.support:support-v4:21.0.2' 
    compile 'org.apache.commons:commons-lang3:3.3.2' 
} 

Czy coś takiego jest możliwe?

Jak uzyskać informacje o artefaktach i smakach w każdym wydaniu? Użyłem $ {artifactId} i $ {flavor} jako symboli zastępczych, ale wiem, że to nie w porządku.

EDIT:

Alright I zorientowali się, jak uzyskać inny artefakt dla każdego smaku. Jednym z klawiszy było ustawienie: Jednak gdy to zrobię, nie otrzymam pliku pom dla każdego artefaktu. Mam przejściowe zależności, które trzeba wciągnąć i nie sądzę, że zostaną wciągnięte bez pom.

Oto mój obecny skrypt gradle, w jaki sposób uzyskać pom wygenerowany dla każdego.

apply plugin: 'com.android.library' 
apply plugin: 'maven' 

group 'com.test' 
version '0.0.1' 

android { 
    compileSdkVersion 19 
    buildToolsVersion "21.1.1" 
    publishNonDefault true 

    defaultConfig { 
     minSdkVersion 14 
     targetSdkVersion 19 
    } 

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

    lintOptions { 
     abortOnError false 
    } 

    packagingOptions { 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/NOTICE.txt' 
    } 

    productFlavors { 
     flavor1 {} 
     flavor2 {} 
    } 
} 

uploadArchives { 
    repositories { 
     mavenDeployer { 
      repository(url: "file://${System.properties['user.home']}/.m2/repository") 

      addFilter('flavor1Release') { artifact, file -> 
       artifact.attributes.classifier.equals("flavor1Release") 
      } 
      addFilter('flavor2Release') { artifact, file -> 
       artifact.attributes.classifier.equals("flavor2Release") 
      } 

      pom('flavor1Release').artifactId = project.archivesBaseName + "-flavor1" 
      pom('flavor2Release').artifactId = project.archivesBaseName + "-flavor2"; 
     } 
    } 
} 

dependencies { 
    compile 'com.android.support:support-v4:21.0.2' 
    compile 'org.apache.commons:commons-lang3:3.3.2' 
} 
+0

Mam dokładnie ten sam problem ... :( – David

+0

Czy to rozwiązane? –

+0

Naprawdę walcząc maven repo, starając się to zrobić. Próbowałem bluszcz repo ale gradle nie będzie budować domyślnych artefaktów ani domyślnych w tym samym czasie Przebudowałem projekt, aby mieć tylko jeden SDK i umieścić smaki w aplikacji zależy od sdk. – lostintranslation

Odpowiedz

1

// Próbowałem w następujący sposób i udało mi się przesłać wiele plików jar. // nadzieję pomóc ....

import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact 

// jarfilename1 and jarfilename2 are the two files that gets upload 
// make sure the artifactID and the file name are the same 


apply plugin: 'java' 
apply plugin: 'maven' 


artifacts{ 
    archives new DefaultPublishArtifact("jarfileName1", "jar", "jar", null, new Date(), new File("build/", "jarfilename1.jar")) 
    archives new DefaultPublishArtifact("jarfileName2", "jar", "jar", null, new Date(), new File("build/", "jarfilename2.jar")) 
} 

uploadArchives { 
    repositories { 
    mavenDeployer { 
     repository(url: "$archivaUrl") { 
     authentication(userName: "$userName", password: "$passWord") 
     } 

     // addfilter for multiple pom upload 
     addFilter("jarfileName1") {artifact, file -> 
         artifact.name == "jarfileName1" 
        } 
     addFilter("jarfileName2") {artifact, file -> 
         artifact.name == "jarfileName2" 
         } 

     //Creating pom files and adding the Entity 
     pom("jarfileName1").version ='1.1.1' 
     pom("jarfileName1").groupId ='what.so.ever' 
     pom("jarfileName1").artifactId ='jarfilename1' 

     pom("jarfileName2").version ='1.1.1' 
     pom("jarfileName2").groupId ='what.so.ever' 
     pom("jarfileName2").artifactId ='jarfilename2' 
    } 
    } 
} 
Powiązane problemy