2
votes

I have a Gradle project which when build creates multiple Jar files based on certain rules like Classes A,B and C goto A.jar, Classes D,E and F goto B.jar and so on.

Now I want to upload these Jar files into Maven repository. Though I am able to do it but I want to put each of these Jars in Maven Repository as a standalone artifact.

For ex: Right now if I have project named MyProject and it has produces 2 Jar files : A.jar and B.jar, then in maven repository i have following structure

-------   Repo
          |
          |----com
               |
               |--- project
                    |
                    |---- MyProject
                          |
                          |---- version 1
                            | 
                            |--- A.jar
                            |--- B.jar 

But i want the following structure

-------   Repo
          |
          |----com
               |
               |--- project
                    |
                    |---- MyProject
                          |
                          |---- A
                            | 
                            |--- Version 1
                              |
                              |--- A.jar
                            |---- B 
                            |
                            |---- Version 1
                               |
                               |--- B.jar

That means i want to make sure that both A.jar and B.jar are two different artifacts in Maven repository, so that I can maintain different version of two.

Right now, In order to put both the jars in maven repository I made sure I add following piece of code in build.gradle.

artifacts {
  archives A,B    
}

One solution would be to have two different Gradle Projects containing the relevant classes and each project producing its own artefact but in my case this can't be short term solution. we already have something like this planned but that has low priority.

1

1 Answers

2
votes

It's all documented in the Gradle User Guide. See Multiple artifacts per project if you are using the "maven" plugin, and Publishing multiple modules if you are using the "maven-publish" plugin.