Multi-project & configurations: Sub-project dependency naming

I have a multi-project with five sub-projects. Two of those sub-projects depend on other subprojects, which I have specified using

project('A') {
   dependencies {
      compile project(':B')
   }
}

The artifact names are modified according to the build configuration like this

uploadReleaseCandidate {
        repositories {
            mavenDeployer {
                ...
                if (!version.contains("-RC")) {
                    pom.version = version + "-RC"
                }
                ...

and similar for -SNAPSHOT and -RELEASE. However, that way all project jars are referencing a “naked” jar name (like org.xyz:A:0.1 rather than org.xyz:A:0.1-RC). So here’s the question:

How do I write my build script so in the generated POM that sub-projects

  • for configuration “snapshot” reference “-SNAPSHOT.jar” files - for configuration “releaseCandidate” reference “-RC.jar” files - for configuration “release” reference “RELEASE” files ?

Thanks for any hints!

What exactly do you mean by “project jar”?

Every project creates a single jar file as an artifact (the project structure is a little similar to OSGi, with interfaces etc. going into one jar file and an implementation of that into another).

And how do these Jars reference other Jar names (“all project jars are referencing a “naked” jar name”)? Are you talking about the ‘dependency’ declarations of the generated POMs?

Like in the first code sample above, with project A adding

compile project(’:B’)

as a dependency.

Sorry, you’ll have to explain in more detail what exactly the problem is. From what I can tell, the build script above just changes the version in the published POM. I can’t tell if/why you want to have it changed somewhere else.

Nono, I am sorry for writing confusing stuff… let me try again…

Let’s say I have a multi-project with two subprojects

MP (no artifact) ±- A (creates org.xyz:A.jar) ±- B depends on A (creates org.xyz:B.jar)

I have three configurations

configurations {
   snapshot
   releaseCandidate
   release
}

The jars are uploaded to an artifactory, and to distinguish the stages the artifact names are modified in the mavenDeployer as detailed above, so e.g.

for project A the candidate artifact is renamed to org.xyz:A:0.1-RC for project B the candidate artifact is renamed to org.xyz:B:0.1-RC

The project dependency is specified as given in the first code sample. Now, when I execute my build e.g. for the uploadReleaseCandidate task the artifact gets uploaded as

<groupId>org.xyz</groupId>
  <artifactId>A</artifactId>
  <version>0.1-RC</version>

and similar for B. However, in B’s POM there is the following dependency

<dependency>
      <groupId>org.xyz</groupId>
      <artifactId>A</artifactId>
      <version>0.1</version>
      <scope>compile</scope>
    </dependency>

(no -RC), and that’s not what I want. I would like to have all RC artifacts reference the RC version of their dependencies from this multi-project (and likewise for snapshots and releases).

Hope this is a little clearer

What’s the artifact for these configurations? Is it always the same Jar as produced by the ‘jar’ task?

Technically (content-wise) it’s the same jar for all configurations, they only differ due to the renaming step.

A simple solution would be to just use a single upload task (‘uploadArchives’) and change ‘project.version’ depending on the value of a system or project property. If you want to keep the separate upload tasks, you’d probably have to reconfigure ‘pom.dependencies’ similar to how you do it for ‘pom.version’.