Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle mavenDeployer - how to include a separate modules code

Tags:

java

gradle

jar

I have a project like this:

MyProject
|-ModuleA
|-ModuleB

Module A is an Android Library that creates an aar, it has a dependency on Module B like so:

 dependencies {
   compile project(':ModuleB')

In ModuleA I am using mavenDepoyer to release locally:

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

This generates me an AAR file and a POM.

When uncompressed the AAR does not contain the class files from Module B and the POM looks like this:

<?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>

As you can see this declares that the AAR has a dependency on ModuleB with an unspecified version. And so if I use this this AAR/POM as a remote, it fails to resolve the dependency 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

I do not want it to try and resolve Module B as another dependency, I want to use the mavenDeployer to be able to create the AAR & POM with Module B included inside, since I have the source code here to do that!


Searched the web to no avail, these sites gave hints but no answer:

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

like image 202
Blundell Avatar asked Feb 06 '26 23:02

Blundell


1 Answers

As far as I know, AARs don't include their dependencies (only APKs do). Instead, transitive dependency resolution will take care of resolving not only the AAR but also its dependencies. The unspecified version is most likely a result of not setting the project.version property in ModuleB.

like image 105
Peter Niederwieser Avatar answered Feb 12 '26 11:02

Peter Niederwieser