我有一个自定义的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
时,将使用正确的内容(包括类.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
运行构建时,编译失败,因为既找不到我的库中的类,也找不到其依赖项中的类。
我正在使用带有 android 构建工具 1.0.0 和新的 maven-publish 机制的 Gradle 2.2.1。
注意:由于缺少库中的类,因此它肯定不仅仅是传递依赖项的问题,因此此解决方案不起作用。我希望从 maven 获取库,因此像这里一样在本地提供它不是一种选择(它对传递依赖项没有帮助)。
没有足够的声誉来评论...
我没有使用新的 maven-plugin,但是如果您使用 android-maven-plugin 部署到 bintray,您只需要将存储库添加到您的 build.gradle 中(或者您可以要求他们将其托管在 jcenter 上,您无需执行任何操作)。然后,您将能够使用 transitive = true
.