Triple-T / gradle-play-publisher

GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
MIT License
4.13k stars 341 forks source link

Cannot add task 'publish' as a task with that name already exists. #768

Closed tprochazka closed 4 years ago

tprochazka commented 4 years ago

It is probably not directly a bug inside of the published plugin. But when I use in my application project default Gradle publish plugin PublishingHelper.PublishPlugin.MAVEN_PUBLISH to upload APK to maven artifactory. It then cause that I can't use published plugin, because it crash on this error

An exception occurred applying plugin request [id: 'com.avast.android.application']
> Failed to apply plugin [class 'org.gradle.api.publish.plugins.PublishingPlugin']
   > Cannot add task 'publish' as a task with that name already exists.

An interesting fact is that it happens only when I'm using plugins {} syntax. On the project where I still using old good apply. I work OK. Or maybe publish plugin just override my publish mechanism to artifactory. I did not try it.

So I'm basically just asking if it is a good idea that plugin adding this task again when it already existing. And if it is possible to simply use the existing one and only depend on it. I mean that "publish" task will doo both things then. Publish to artifactory and also to the play.

SUPERCILEX commented 4 years ago

https://github.com/Triple-T/gradle-play-publisher/issues/621#issuecomment-510541800

SUPERCILEX commented 4 years ago

It should work fine as long as GPP is applied after the maven plugin.

tprochazka commented 4 years ago

Maven plugin is applied directly inside of my plugin, which is applied before GPP plugin. It looks like this

plugins {
  my-plugin
  gpp
}

and in this situation, it crashes

But when I do the same with

apply my-plugin
appy gpp

it works.

Sadly I need to make it work also with plugins, since this is now suggested way.

Maybe plugins not preserve apply order :-(

SUPERCILEX commented 4 years ago

Yeah, looks like the order isn't being preserved. Either way, there's not much GPP can do. You can do something like this: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl. Add GPP with apply false, then immediately apply the plugin manually below.

tprochazka commented 4 years ago

Hmm, it looks that "apply false" make sense only if you want to declare plugin in parent gradle file, but then apply them only in some of the submodules.

SUPERCILEX commented 4 years ago

But you should be able to do this:

plugins {
  my-plugin
  gpp apply false
}
apply(plugin=gpp)
tprochazka commented 4 years ago

Yes. This works. I tried it before, but I had bad syntax there :-( Thanks. But I was expected that they solved possible dependency between two plugins in some better way :-( Or there should be a way how to write a plugin to be independent on the other plugin order.

SUPERCILEX commented 4 years ago

Yeah, it'd be nice if they had a built-in way of distinguishing tasks from each plugin.