java - Gradle mavenDeployer - 如何包含单独的模块代码

标签 java jar gradle

我有这样一个项目:

MyProject
|-ModuleA
|-ModuleB

模块 A 是一个创建 aar 的 Android 库,它依赖于模块 B,如下所示:

 dependencies {
   compile project(':ModuleB')

在 ModuleA 中,我使用 mavenDepoyer 在本地发布:

uploadArchives {
    repositories.mavenDeployer {
        pom.groupId = "com.foo"
        pom.artifactId = "bar"
        pom.version = "1.0"
        repository(url: "file://${localReleaseDest}")
    }
}

这会生成一个 AAR 文件和一个 POM

当解压缩 AAR 不包含模块 B 中的类文件 POM 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.foo</groupId>
  <artifactId>bar</artifactId>
  <version>1.0</version>
  <packaging>aar</packaging>
  <dependencies>
    <dependency>
      <groupId>MyProject</groupId>
      <artifactId>ModuleB</artifactId>
      <version>unspecified</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

如您所见,这声明 AAR 依赖于未指定版本的 ModuleB。因此,如果我将此 AAR/POM 用作远程,它无法解析依赖项 ModuleB。

Error:A problem occurred configuring project ':example'.
 Could not resolve all dependencies for configuration ':example:_debugCompile'.
    Could not find MyProject:ModuleB:unspecified.
     Searched in the following locations:
         https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.pom
         https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.jar
     Required by:
         Test:example:unspecified > com.foo:MyProject:1.0

我不希望它尝试将模块 B 解析为另一个依赖项,我想使用 mavenDeployer 来创建 AARPOM模块 B 包含在里面,因为我这里有源代码来做到这一点!


网上搜索无果,这些网站给出了提示但没有答案:

How to publish apks to the Maven Central with gradle?

how to tell gradle to build and upload archives of dependent projects to local maven

http://www.gradle.org/docs/current/userguide/artifact_management.html

http://gradle.org/docs/current/userguide/userguide_single.html#sub:multiple_artifacts_per_project

http://gradle.org/docs/current/userguide/userguide_single.html#deployerConfig

最佳答案

据我所知,AAR 不包含它们的依赖项(只有 APK 包含)。相反,传递依赖解析不仅会解析 AAR,还会解析它的依赖。未指定的版本很可能是未在 ModuleB 中设置 project.version 属性的结果。

关于java - Gradle mavenDeployer - 如何包含单独的模块代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26939628/

相关文章:

java - 替换 StringBuilder 中的字符

java - 在 android 中创建数据表的最佳方法是什么?

java - 使用 JPA : what queries should I write to get the same result I get in JDBC? 加入

java - ECLIPSE:java.lang.NoClassDefFoundError:无法初始化类 ****

android-studio - Android Studio 1.1.0的Gradle同步失败

Gradle, "sourceCompatibility"vs "targetCompatibility"?

java - 在 crate.yml 中启动具有特定 HEAP 数量的节点

java - 如何运行一个包含依赖库的jar?

java - 如何使用批处理文件无限循环需要参数的 jar 文件?

gradle - 如何多次执行Gradle任务?