wojciech_maciejewski
wojciech_maciejewski

Reputation: 1319

how to execute "gradle publishToMavenLocal" from bulid.gradle file in android library

I would like to publish my android library to maven repo ( for now only local repository) so i use maven-publish plugin and use terminal gradle publishToMavenLocal command to do that.

Is there any possibility to add that command to build.gradle so the publishing task will trigger always on build?

And the second question, is there any possibility to add dependency to pom file automatically from aar , because gradle dont do that by default, for now I'm using solution found here Gradle not including dependencies in published pom.xml.

Cheers Wojtek

Upvotes: 1

Views: 3440

Answers (1)

Stanislav
Stanislav

Reputation: 28136

Is there any possibility to add that command to build.gradle so the publishing task will trigger always on build?

Yes, it is possible. If you know the name of the build task, which have to trigger a publishing, you can use the finalizedBy property of the task, you can read about it here, like:

someBuildTask.finalizedBy publishToMavenLocal

In this case, task publishToMavenLocal will be always triggered after the someBuildTask. But you have to know, it will be triggered, even if build task fails, so it may need some additional configuration to skip it's execution if build task was failed.

But, IMO, it's preffered to make it other way, I mean, make a publishing dependent from build tasks and call not a build, but publishing task instead. In that case, you will be able to call a build with and without artifacts publishing.

Upvotes: 3

Related Questions