Make tests depend on another project?

I’ve got a large repo with multiple projects in it. I have one which compiles the project into a single package. This one depends on the build phase of all the other projects.

I want to install the resulting compiled package, and then run unit tests on some of the projects that have already built. Is it possible to run projects like this? :project1:build -> project2:build -> project1:test

This is what I’ve got so far. It’s not working obviously, but it seems like it should.

if (project.hasProperty('integrationTestCategory')) {
    test.dependsOn {
        ':rpm:build'
        'stopServicesForIntegrationTests'
    }
}

test {
    useJUnit { excludeCategories 'com.organization.util.IntegrationTest' }
    if (project.hasProperty('integrationTestCategory')) {
        useJUnit { includeCategories project.integrationTestCategory }
    }
}

task setupRepoFile(type: Copy) {
    from "${projectDir}/src/test/resources/organization.repo"
    into '/etc/yum.repos.d'
}

task installForIntegrationTests(type: Exec, dependsOn: ':rpm:build') {
    dependsOn 'setupRepoFile'
    String rpmPkg = project(':rpm').rpmBuild.getArtifactPath('server')
    commandLine 'sudo', 'yum', '-y', 'install', rpmPkg
}

task stopServicesForIntegrationTests(type: Exec, dependsOn: installForIntegrationTests) {
    dependsOn 'installForIntegrationTests'
    doLast {
        commandLine 'sudo', 'service', 'project-server', 'stop'
    }
}

The above code runs the integration test (or tries to) before the ‘:rpm’ project has built (seemingly ignoring the dependencies), which fails as the artifact does not yet exist.