我有一个Kotlin Android库,我试图发布到我设置的s3 maven repo。一切正常,但我似乎无法看到消息来源。这就是我所拥有的
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier 'sources'
}
publishing {
repositories {
maven {
url awsUrl
credentials(AwsCredentials) {
accessKey awsAccessKey
secretKey awsSecretKey
}
}
}
publications {
aar(MavenPublication) {
groupId = "com.example"
artifactId = "library-0"
version = libraryVersionName
artifact("$buildDir/outputs/aar/${project.name}-debug.aar")
artifact(sourceJar)
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
if(it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
project.tasks.whenTaskAdded { addedTask ->
if (addedTask.name == 'generatePomFileForMavenJavaPublication') {
addedTask.dependsOn assembleDebug
}
}
在我的应用中,我添加了maven repo网址,并将图书馆包括在内:
implementation 'com.example:library-0:1.0.0-SNAPSHOT'
一切正常,应用程序构建,库运行良好。唯一的问题是当我去查看任何类/函数的来源时,我只看到函数存根说编译代码而没有javadoc。有什么东西我应该与源jar做不同的事情吗?
更新
我已将发布更改为aar
,并查看了我的.gradle/caches/
目录,该目录现在包含我的库:
AndroidManifest.xml
R.txt
jars/classes.jar
res/layout/**
res/values/**
jar/classes.jar
包含所有已编译的.class
文件和proguard文件。在上传过程中,我确实看到我已上传:
library-0-1.0.0-20180306.153335-5.aar
library-0-1.0.0-20180306.153335-5.aar.md5
library-0-1.0.0-20180306.153335-5.aar.sha1
library-0-1.0.0-20180306.153335-5.pom
library-0-1.0.0-20180306.153335-5.pom.md5
library-0-1.0.0-20180306.153335-5.pom.sha1
library-0-1.0.0-20180306.153335-5-sources.jar
library-0-1.0.0-20180306.153335-5-sources.jar.md5
library-0-1.0.0-20180306.153335-5-sources.jar.sha1
更新
作为一个额外的参考,我找到了一个具有类似发布的库的示例:http://central.maven.org/maven2/com/mcxiaoke/volley/library-aar/1.0.1/在这里,看起来它与附加的-sources
具有相同的结构。 .pom
文件看起来不需要指定任何特殊内容。作为参考,这里是我的.pom
文件:
<?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>library-0</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre7</artifactId>
<version>1.2.30</version>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>27.1.0</version>
</dependency>
<dependency>
<groupId>com.android.support.constraint</groupId>
<artifactId>constraint-layout</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>android.arch.lifecycle</groupId>
<artifactId>extensions</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide</artifactId>
<version>4.6.1</version>
</dependency>
</dependencies>
</project>
答案 0 :(得分:0)
尝试替换
mavenJava(MavenPublication)
带
aar(MavenPublication)
答案 1 :(得分:0)
你试试这个gradle插件,很容易发布aars或jar: