How to set moduleName of project dependency


(Justin) #1

Gradle sets same project name instead of artifact baseName for project dependencies.

name 'root'
group 'org.group'
version '1.0.0-SNAPSHOT'
configurations {
    foo
    bar
}
task fooJar { baseName = 'root-foo' }
task barJar { baseName = 'root-bar' }
artifacts {
    foo fooJar
    bar barJar
}

Other project:

dependencies {
    compile project(path: ':root', configuration: 'foo')
}

publishing.publications.each {
    it.pom.withXml {
        def dependencies = asNode().appendNode('dependencies')
        configurations.compile.getResolvedConfiguration().getFirstLevelModuleDependencies().each {
            def dependency = dependencies.appendNode('dependency')
            dependency.appendNode('groupId', it.moduleGroup)
            dependency.appendNode('artifactId', it.moduleName)
            dependency.appendNode('version', it.moduleVersion)
       }
   }
}

Produces POM with:
org.group
root
1.0.0-SNAPSHOT

Does Gradle have or need something like:

artifacts {
    foo fooJar { moduleName 'root-foo' }
    bar barJar { moduleName 'root-bar' }
}

Or is there some other way to set module name of different artifacts for correct inclusion in pom?