Running tests before maven-publish

Hi,

Just wondering what’s the Gradle way to make sure tests are run before publishing to a maven repo

I’ve tried

publish.dependsOn test

however that runs the tests after it uploads.

I figure I need to make sure tests run before publishMavenJavaPublicationToMavenRepository yet it seems that task doesn’t exist until after the build.gradle has been processed. Therefore the follow doesn’t work:

tasks.getByName(‘publishMavenJavaPublicationToMavenRepository’).mustRunAfter(test)

The following works but I don’t like it:

tasks.publish.dependsOn(test)

tasks.whenTaskAdded{t->

if( t.name == “publishMavenJavaPublicationToMavenRepository”){

t.mustRunAfter(test)

}

}

Thanks.

This would probably do the trick:

tasks.withType(PublishToMavenRepository) { it.dependsOn test }
1 Like

Thanks Gary. That worked perfectly.