A GradleBuild task is executing a separate build. The test task would be excluded from the build that you run directly, not the build being run by your publish task.
The excluded tasks are not automatically inherited from the parent build. However, if you would like to propagate these options down, it is easy to do so without hardcoding the exclusion: