我有一个结构如下的项目。它有一个'main-module
' 这是我们开发的重点,它应该能够将两个变体(调试、发布)的 AAR 发布到 Nexus。我们还有一堆其他依赖模块和一个测试应用程序。
project
|
|- app
|- main-module
|- module-a
|- module-b
...
我正在寻找运行将打包 main-module
的构建。 AAR 然后将这两个上传到 Nexus 存储库。调试 AAR 将转到快照存储库,发布版本将转到发布存储库。我有一些拼图,但我不太确定如何将它们拼凑在一起。
是)我有的:
构建 AAR gradlew assemble
发布 AAR
project.uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/nexus/content/repositories/snapshots/") {
authentication(userName: "deployment", password: "password123")
}
pom.version = "0.0.1-SNAPSHOT"
pom.artifactId = "MainModule"
pom.groupId = "com.myorg.test"
}
}
构建工作,我可以将一个版本推送到 Nexus。我不知道如何为调试和发布版本提供配置,以便它们具有正确的存储库(例如
/snapshots
与 /release
)和正确的版本(发布版本名称不包含 SNAPSHOT
)。一旦工作,我会将名称、版本和凭据移到属性中,在有人指出之前,凭据不会 checkin 源代码控制。
使用:
最佳答案
因此,经过几天的挖掘,我找到了解决方案。这很粗糙,我还没有优化它,但解决方案有效。请注意,它假定您的 aar 文件在名称中包含文本“调试”和“发布”,如果它们不包含,那么您可以调整到您的项目。我不知道这如何适用于不仅仅是调试和发布变体的模块,或者是否涉及产品风格。
android-maven-gradle-plugin
整合android-maven-gradle-plugin .步骤在文档链接中。
模块 build.gradle apply plugin: 'com.github.dcendents.android-maven'
afterEvaluate {
uploadArchives {
repositories {
mavenDeployer {
addFilter('debug') { artifact, file ->
artifact.name.contains("debug")
}
addFilter('release') { artifact, file ->
artifact.name.contains("release")
}
pom('debug').groupId = 'com.yourgroup'
pom('release').groupId = 'com.yourgroup'
pom('debug').artifactId = "MyArtifact"
pom('release').artifactId = "MyArtifact"
pom('debug').version = android.defaultConfig.versionName + "-SNAPSHOT"
pom('release').version = android.defaultConfig.versionName
pom.packaging = 'aar'
repository(url: "http://localhost:8081/nexus/content/repositories/releases/") {
authentication(userName: 'user'), password: 'pwd')
}
snapshotRepository(url: "http://localhost:8081/nexus/content/repositories/snapshots/") {
authentication(userName: 'user'), password: 'pwd')
}
}
}
}
}
关于Android - 多个 AAR 变体 Nexus 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53093633/