2014-11-14 53 views
2

我有這樣一個項目:搖籃mavenDeployer - 如何將一個單獨的模塊代碼

MyProject的
| -ModuleA
| -ModuleB

模塊A是一款Android庫那創建一個aar,它對模塊B有如下依賴:

dependencies { 
    compile project(':ModuleB') 

In M oduleA我使用mavenDepoyer局部釋放:

uploadArchives { 
    repositories.mavenDeployer { 
     pom.groupId = "com.foo" 
     pom.artifactId = "bar" 
     pom.version = "1.0" 
     repository(url: "file://${localReleaseDest}") 
    } 
} 

這產生了我一個AAR文件和POM

當未壓縮的AAR不會從模塊B 包含的類文件和POM看起來是這樣的:

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.foo</groupId> 
    <artifactId>bar</artifactId> 
    <version>1.0</version> 
    <packaging>aar</packaging> 
    <dependencies> 
    <dependency> 
     <groupId>MyProject</groupId> 
     <artifactId>ModuleB</artifactId> 
     <version>unspecified</version> 
     <scope>compile</scope> 
    </dependency> 
    </dependencies> 
</project> 

正如你可以看到這個聲明,AAR有一對ModuleB的依賴未指定的版本。因此,如果我將此AAR/POM用作遠程,它無法解析依賴性ModuleB。

Error:A problem occurred configuring project ':example'. 
Could not resolve all dependencies for configuration ':example:_debugCompile'. 
    Could not find MyProject:ModuleB:unspecified. 
    Searched in the following locations: 
     https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.pom 
     https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.jar 
    Required by: 
     Test:example:unspecified > com.foo:MyProject:1.0 

我不希望它試圖解決模塊B作爲另一個依賴,我想用mavenDeployer能夠創建AAR & POM與模塊B包括裏面,因爲我的源代碼這裏要做到這一點!


在網上搜索,無果,這些網站給的提示,但沒有回答:

How to publish apks to the Maven Central with gradle?

how to tell gradle to build and upload archives of dependent projects to local maven

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

http://gradle.org/docs/current/userguide/userguide_single.html#sub:multiple_artifacts_per_project

http://gradle.org/docs/current/userguide/userguide_single.html#deployerConfig

回答

2

據我所知,AARs不包括它們的依賴關係(只有APK)。相反,傳遞依賴解決方案不僅能解決AAR問題,還能解決它的依賴問題。未指定的版本很可能是因爲未在ModuleB中設置project.version屬性。

+1

因此,如果我將生成的aar&pom上傳到maven central,我還需要單獨上傳'ModuleB' jar來解決它?似乎我應該只使用一個模塊來避免麻煩... – Blundell 2014-11-14 22:40:38

+0

是的,這就是它通常的做法。有可能是將A模塊包含在AAR中的一種方式,但我不知道有關這方面的任何細節,我不認爲這是正常的。 (它當然不是在Java的土地上。)你可以發佈到你自己的[Bintray](https://bintray.com/)存儲庫(它一旦被包含在JCenter中,也可以發佈到Maven Central)同步到Maven Central)。 – 2014-11-14 22:44:52