I have now managed to convert some larger multi project build from maven and it works fine. For publishing artifacts, I use the maven-publish plugin. Publishing works fine to out corporate repository when I define the publishing{repositories{maven {…}}} code in each subproject. This is a lot of duplication and I would rather like to define just the repositories in the root project.
I tried to import or not maven-publish, define the publishing{repositories{maven {…}}} block in the root or inside subproject block, but to no avail. When I do a gradle tasks for root project or one of the subprojects, the task publishJarPublicationToMyCorporateMavenLocalRepository does not show up.
Any idea what I do wrong here would be appreciated.
sure. I created a very simple project using gradle 2.4 with one subproject (please find the gradle file content near the bottom of this message). You can just do a “gradle init —type java-library”, create a folder ‘sub’ move the src folder into it and put the below gradle file contents.
In the below form, a “gradle tasks” prints the publishing task just fine:
publishJarPublicationToMyCompanyDevMavenRepository - Publishes Maven publication ‘jar’ to Maven repository ‘myCompanyDevMaven’.
Now I would like to define the publishing{repositories{}}} definition block in the root project instead of each sub project (here only one for brevity).
By looking at the source code from MavenPublishPlugin, the tasks shall be created by mutating the tasks container (using new rules mechanism). The rule based mechanism ensures that the mutate rule inputs (eg the PublishingExtension) are fully realized before the rule is executed. So the PublishingExtension shall be realized and therefore contain the repositories you added.
Maybe this does not work well with subprojects and ‘by type’ declarations. Anyone has a better idea?
At this time, only repositories created by the ivy() factory method have any effect. Please see IvyPublication for information on how this can be used for publishing to Ivy repositories.
I am not absolutely sure, but as I use maven repositories this might well explain the problem, or what do you think?
For now I dropped back to groovy, defined a method in the root project like this:
In my own use cases, I use the ivy-publish plugin.
I assumed it was purely identical with the maven-publish plugin.
It seems not to be the case at the moment.
But this seems weird anyway, because when you compare