我使用
我的库有其他依赖项,这些依赖项也是
如何从
生成
我找到了一些类似事情的解释:
maven-publish
插件来部署 Android 库(.aar
)。我的库有其他依赖项,这些依赖项也是
.aar
。如何从
build.gradle
的 dependencies
部分导入所有依赖项?dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile ('com.android.support:recyclerview-v7:22.2.1'){
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
//Http communication, websockets, etc.
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
//Fonts
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
//Unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
//Other
compile ('org.apache.commons:commons-lang3:3.4'){
exclude group: 'org.apache.httpcomponents'
}
//Reactive programmnig
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
}
生成
pom.xml
的dependencies
部分:<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.sdk</groupId>
<artifactId>SDK</artifactId>
<version>0.0.1</version>
<packaging>aar</packaging>
<dependencies>
...
</dependencies>
</project>
我找到了一些类似事情的解释:
https://issues.gradle.org/browse/GRADLE-1749
因此,我理解应该使用pom.withXml
,从project.configurations.compile.allDependencies
导入所有依赖项,并将其范围设置为compile
,然后将其放入asNode().dependencies
中。
但是我不熟悉它,我认为我做错了什么。这是我的当前代码:
publishing {
publications {
maven(MavenPublication) {
artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar"
artifactId = POM_ARTIFACT_ID
groupId = GROUP
version = VERSION_NAME
// Task androidSourcesJar is provided by gradle-mvn-push.gradle
//artifact androidSourcesJar {
// classifier "sources"
//}
pom.withXml {
def depsNode = asNode().dependencies.'*'
project.configurations.compile.allDependencies.each { dep ->
if(dep.name != null && dep.group != null && dep.version != null) {
def depNode = new Node(null, 'dependency')
def groupIdNode = new Node(depNode, 'groupId', dep.getGroup())
def artifactIdNode = new Node(depNode, 'artifactId', dep.getName())
def versionNode = new Node(depNode, 'version', dep.getVersion())
depsNode.add(depNode)
println depsNode
}
}
}
}
}
repositories {
maven {
credentials {
username System.getenv('NEXUS_USER_NAME')
password System.getenv('NEXUS_PASSWORD')
}
url "http://nexus-repo"
}
}
}
pom.withXml
修改生成的 pom.xml 文件,但是您不应该需要进行任何自定义配置来包括所有运行时依赖项(默认情况下也包括编译依赖项)。您遇到的问题是什么? - RaGepom.xml
没有任何依赖项。但我希望它具有所有带有“compile”范围的依赖项。 - Aleksandr.aar
依赖项并将其包含在另一个应用程序中时,我需要包含来自我的库项目的所有依赖项,因为我总是会收到ClassNotFoundException
。 - Aleksandrcompile
依赖项在pom.xml文件中正确编写。我想你的情况可能不同,因为这是一个Android项目 - 我找到了一个专门用于发布.aar文件的Android插件 - 下面发布。 - RaGe