Gradle 8:":p ublishMavenPublicationToMavenRepository"使用任务':bundleReleaseAar'的输出,而不声明显式或隐式依赖项



当我更新Gradle -wrapper使用Gradle 8.0时,我遇到了这个问题。我有两个错误:

1. Task ':publishMavenPublicationToMavenRepository' uses this output of task ':androidSourcesJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
2. Task ':publishMavenPublicationToMavenRepository' uses this output of task ':bundleReleaseAar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

我的build.gradle文件是这样的。

buildscript {
...
}
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
task sourceJar(type: Jar) {
from android.sourceSets.main.jniLibs.srcDirs
classifier "sources"
}
version = '8.0.0'
android {
...
}
dependencies {
...
}
android.libraryVariants.all {
def aptOutputDir = new File(buildDir, "generated/source/apt/${it.unitTestVariant.dirName}")
it.unitTestVariant.addJavaSourceFoldersToModel(aptOutputDir)
}
publishing {
publications {
maven(MavenPublication) {
version = version
artifactId = "your_artifact_id"
groupId = "com.yourgroup.id"
artifact(sourceJar)
artifact("$buildDir/outputs/aar/libraryname-release.aar")
}
}
repositories {
maven {
def releasesUrl = "releaseurl_ifavailable"
def snapshotsUrl = "snapshoturl_ifavailable"
url = version.endsWith('SNAPSHOT') ? snapshotsUrl : releasesUrl
credentials {
username = your_username
password = your_password
}
}
}
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
}

当我试图发布我的库时,我收到了这些错误。

我已经有了解决方案,我会把它贴在解决方案部分。

我找到了答案。

现在我的build.gradle文件看起来像这样:

buildscript {
...
}
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
version = '8.0.0'
android {
...
}
dependencies {
...
}
android.libraryVariants.all {
def aptOutputDir = new File(buildDir, "generated/source/apt/${it.unitTestVariant.dirName}")
it.unitTestVariant.addJavaSourceFoldersToModel(aptOutputDir)
}
task sourceJar(type: Jar) {
from android.sourceSets.main.jniLibs.srcDirs
archiveClassifier = "sources"
}
task androidSourcesJar(type: Jar) {
archiveClassifier.set("sources")
from android.sourceSets.main.java.sourceFiles
}
afterEvaluate {
publishing {
publications {
maven(MavenPublication) {
from components.release
version = version
artifactId = "your_artifactId"
groupId = "com.yourgroup.id"
}
}
repositories {
maven {
def releasesUrl = "releaseurl_ifavailable"
def snapshotsUrl = "snapshoturl_ifavailable"
url = version.endsWith('SNAPSHOT') ? snapshotsUrl : releasesUrl
credentials {
username = your_username
password = your_password
}
}
}
}
}

基本上,我必须为Android库的发布添加一个afterEvaluate标签。

另外,我删除了aar文件将要发布的路径,因为from components.release为我做了这件事。

我希望这能帮助像我一样无法找到这个特定问题的答案的人。

Mayank Pandit,你的答案是正确的(在这里),将publishing块嵌入afterEvaluate块中,并用from components.release替换artifact("$buildDir/outputs/aar/libraryname-release.aar")声明。

如果您比较问题和答案中的build.gradle文件,您将看到您也删除了artifact(sourceJar)声明。这意味着你的Android库现在将在没有源代码的情况下发布。

如果你想发布Android库及其源代码并支持Javadoc,你需要对build.gradle文件做两个修改,如下所述。

首先,在android块中添加publishing块,如下所示:

android {
publishing {
singleVariant("release") {
withJavadocJar()
withSourcesJar()
}
}
}

其次,将maven(MavenPublication)更改为release(MavenPublication)

完成这两个更改后,您可以摆脱sourceJar任务。

参考Android Gradle Plugin>发布你的库文档页面,获取关于如何发布Android库的最新指导。

相关内容

  • 没有找到相关文章

最新更新