1
votes

I'm having multi-project Gradle config:

-- root (folder 'gradle_test')
   L--wrapper (depends on some 3rd-party maven libs)
   L--module1 (depends on wrapper)
   L--app

I need module1 jar (and wrapper jar as transitive dependency) to be published in local maven repo.

root build.gradle:

// for maven
ext {
    groupId = 'mygroup'
    version = '3.0'
}

wrapper build.gradle:

apply plugin: 'maven'
...
// maven pom
install {
    repositories.mavenInstaller {
        pom.groupId = rootProject.ext.groupId
        pom.artifactId = 'wrapper'
        pom.version = rootProject.ext.version
    }
}

module1 build.gradle:

dependencies {
    compile project(':wrapper')

    ...
}
// maven pom
install {
    repositories.mavenInstaller {
        pom.groupId = rootProject.ext.groupId
        pom.artifactId = 'module1'
        pom.version = rootProject.ext.version
    }
}

Howeven when installing module1 into local maven cache i can see dependency to 'wrapper' module is generated incorrectly (version is not specified). module1 pom.xml in repo:

<?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>mygroup</groupId>
  <artifactId>module1</artifactId>
  <version>3.0</version>
  <dependencies>
    <dependency>
      <groupId>gradle_test</groupId>     // error 1: gradle project name (instead of overriden mvn groupId)
      <artifactId>wrapper</artifactId>
      <version>unspecified</version>     // error 2: not set at all
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

In other words Gradle does not use maven module groupId/artifactId/version for maven dependencies mapped from compile project(:wrapper) declaration.

How can i do/fix it?

1

1 Answers

0
votes

I had to write for wrapper and module1:

// mvn
group = rootProject.ext.groupId
version = rootProject.ext.version

and you can remove:

install {
    repositories.mavenInstaller {
    ...
    }
 }

since Gradle will use project.group as mvn module groupId and project.version as mvn module version:

https://docs.gradle.org/current/userguide/maven_plugin.html#sec:maven_pom_generation