我有一个自定义的android库发布到我的本地maven存储库,使用以下build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
apply plugin: "com.android.library"
apply plugin: "maven-publish"
group = "com.example"
//name = "mylibrary"
version = "0.0.1"
repositories {
mavenCentral()
mavenLocal()
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
versionCode 1
versionName project.version
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile "org.slf4j:slf4j-api:1.7.5"
}
publishing {
publications {
android(MavenPublication) {
artifact bundleRelease
//FIXME manually add the dependencies as gradle doesn't find them in the default configuration
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.default.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
运行 ./gradlew publishToMavenLocal
时,使用正确的内容(包括classes.jar)和正确的mylibrary-0.0.1.pom创建文件 ~/.m2/repository/com/example/mylibrary/0.0.1/mylibrary-0.0.1.aar
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mylibrary</artifactId>
<version>0.0.1</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
</project>
但是当我在另一个项目中将此库的依赖声明为 compile "com.example:mylibrary:0.0.1@aar"
时,即使它似乎被发现,也不包括库及其依赖项 . ./gradlew dependencies
收益率
compile - Classpath for compiling the main sources.
\--- com.example:mylibrary:0.0.1
运行构建时,编译失败,因为我的库中的类和其依赖项中的类都没有找到 .
我正在使用Gradle 2.2.1和android构建工具1.0.0以及新的maven-publish机制 .
注意:由于缺少库中的类,它必须不仅仅是传递依赖的问题,因此this解决方案不起作用 . 我希望从maven中获取库,因此像here那样在本地提供它不是一个选项(并且它对传递依赖性没有帮助) .
1 回答
没有足够的声誉评论......
我没有使用新的maven-plugin,但是如果你使用android-maven-plugin部署到bintray,你只需要将repo添加到你的build.gradle(或者你可以让他们在jcenter上托管它,你就不要't have to do anything). Then you' ll能够使用
transitive = true
.