However, when I type gradle distTar, it does create the dist file aforementioned, and after that I can run gradle publish. How do I make the publish task depend on distTar? I tried adding publications (dependsOn:‘distributions’) but that did not work as I get:
Could not find method publishing() for arguments [{dependsOn=distributions}, ...
Assuming the task ‘distTar’ is of type ‘Tar’ then you can simply do ‘artifact distTar’ which creates an implicit dependency. In fact, you can pass any instance of ‘AbstractArchiveTask’ to the ‘artifact()’ method.
The end result of Mickey’s solution is the same. In that case you are simply explicitly stating the build dependency, rather than having Gradle infer it from the task.