Unfortunately applying the ‘java’ plugin automatically adds the jar task as an artifact. Simply disabling the task will (as you discovered) result in an error because we will attempt to publish an artifact that doesn’t exist. Might I suggest using the ‘maven-publish’ plugin instead? That way you can explicitly configure your publications.
We already use such plugin for publishing. But this does not solve the problem. The central publishing task iterate over the artifacts to configure the publishing. Also a check with File.exists does not help. Because a missing artifact is of course an error condition.