How to publish different artifacts created in one project into different Artifactory repositories


First, this is a question related to the Artifactory publish plugin. I’m not sure whether this forum is the right place to post this question to; there doesn’t seem to be a user forum dedicated to the Artifactory plugin maintained by JFrog. So, let me try …

While it is possible to publish artifacts of different projects into different repositories, my use case is different: I have a single project in which I create two artifacts. I want to publish them into different Artifactory repositories. Is that possible?

I’ve managed to define one publication for each artifact

publishing {
   publications {
      foo(MavenPublication) { ... }
      blah(MavenPublication) { ... }

What is not clear to me is how to tell the Artifactory plugin to use different repositories for each publication.

You need to make either seperate build projects or build separately with different configurations.
I have a similar issue publishing .jar and .rpm files. JFrog support told me to make 2 build projects.
Not only that, but in the context of a CI Server (TeamCity) – they had to be totally seperate ‘builds’. There is a lot of global state passed around as system and gradle properties that is ‘assumed’ to all refer to a single build and configuration.

I ended up with a solution that the first build (.war and .jar) published to Artifactory in Repository “A” (maven type),
then the second build resolved against Repository “A” to get the artifacts, and publish to Repository “B” (rpm type).

You might be able to use virtual repositories and the default publish setting creatively … that would only conceivably work if the repositories were the same type. I could not figure out a way to do it though.

Hi David

What you are saying is essentially confirming my conclusion: there is no direct support for this use case, but it can be done using separate builds.

Eventually, I ended up with a similar approach: in order not to complicate matters, I have defined two build scripts for my project: the standard one build.gradle and a second one, say, secondary.gradle, which creates and publishes the second artifact. I start the secondary build using gradle -b secondary.gradle.

If it works for your situation, you might be able to disable the publish tasks you do not need while keeping everything in a single build file. Something similar to this thread.