Obtaining ProjectPublications using GradleConnector

Hi everyone!
I am looking for a way to find out what a given project will publish to a local/remote Maven repo when the corresponding task is executed w/o modifying the project scripts. It looks like org.gradle.tooling.model.gradle.ProjectPublications is supposed to provide that info but I can’t seem to get it populated.
For example, if I take the GitHub - apache/kafka: Mirror of Apache Kafka project. I tried something like

final ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(kafkaProjectDir).connect();
try {
    final ProjectPublications publications = connection.model(ProjectPublications.class).forTasks("generatePomFileForMavenJavaPublication").get();
} finally {
    connection.close();
}

The publications I receive are always empty, although I can see the pom-default.xml files generated. Or do I have to actually publish the project to get that model populated?

Thanks!

Figured it out.

	public static class PublicationReader implements BuildAction<List<GradleModuleVersion>> {

		@Override
		public List<GradleModuleVersion> execute(BuildController controller) {
			GradleProject project = controller.getModel(GradleProject.class);
			List<GradleModuleVersion> publications = new ArrayList<>();
			getPublications(project, controller, publications);
			return publications;
		}
		
		private void getPublications(GradleProject project, BuildController controller, List<GradleModuleVersion> publications) {
			ProjectPublications pp = controller.getModel(project, ProjectPublications.class);
			for (GradlePublication pub : pp.getPublications()) {
				publications.add(pub.getId());
			}
			for(GradleProject child : project.getChildren()) {
				getPublications(child, controller, publications);
			}
		}
	}

	public static class PublicationReaderOutcome implements ResultHandler<List<GradleModuleVersion>> {

		private CompletableFuture<List<GradleModuleVersion>> publications = new CompletableFuture<>();
		
		public List<GradleModuleVersion> getPublications() {
			try {
				return publications.get();
			} catch (Exception e) {
				throw new RuntimeException("Failed to obtain publications", e);
			}
		}
		
		@Override
		public void onComplete(List<GradleModuleVersion> result) {
			publications.complete(result);
		}

		@Override
		public void onFailure(GradleConnectionException failure) {
			failure.printStackTrace();
		}
	}
	
	public static void main(String[] args) throws Exception {

		final ProjectConnection connection = GradleConnector.newConnector()
				.forProjectDirectory(projectDir)
				.connect();

		try {
			final PublicationReaderOutcome outcome = new PublicationReaderOutcome();
			connection.action(new PublicationReader())
			.setStandardOutput(System.out)
			.run(outcome);
			
			List<GradleModuleVersion> publications = outcome.getPublications();
			log("PROJECT PUBLICATIONS:");
			publications.forEach(p -> log(p.getGroup() + ":" + p.getName() + ":" + p.getVersion()));
		} finally {
			connection.close();
		}
        }