Code review comment: If the project went through the `package` phase then it will be the JAR.

Code before review:
public void execute() throws MojoExecutionException {
if (project.getPackaging().equals("pom")) {
getLog().info("Type of the artifact is POM, skipping build goal");
return;
}
if (skip) {
getLog().info("Skipping Quarkus build");
return;
}
boolean clear = false;
try {
final Properties projectProperties = project.getProperties();
final Properties realProperties = new Properties();
for (String name : projectProperties.stringPropertyNames()) {
if (name.startsWith("quarkus.")) {
realProperties.setProperty(name, projectProperties.getProperty(name));
}
}
if (uberJar && System.getProperty(QUARKUS_PACKAGE_UBER_JAR) == null) {
System.setProperty(QUARKUS_PACKAGE_UBER_JAR, "true");
clear = true;
}
realProperties.putIfAbsent("quarkus.application.name", project.getArtifactId());
realProperties.putIfAbsent("quarkus.application.version", project.getVersion());
MavenArtifactResolver resolver = MavenArtifactResolver.builder()
.setWorkspaceDiscovery(false)
.setRepositorySystem(repoSystem)
.setRepositorySystemSession(repoSession)
.setRemoteRepositories(repos)
.build();
final Artifact projectArtifact = project.getArtifact();
final AppArtifact appArtifact = new AppArtifact(projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
projectArtifact.getClassifier(), projectArtifact.getArtifactHandler().getExtension(),
projectArtifact.getVersion());
File projectFile = projectArtifact.getFile();
if (projectFile == null) {
projectFile = new File(project.getBuild().getOutputDirectory());
if (!projectFile.exists()) {
if (hasSources(project)) {
throw new MojoExecutionException("Project " + project.getArtifact() + " has not been compiled yet");
}
if (!projectFile.mkdirs()) {
throw new MojoExecutionException("Failed to create the output dir " + projectFile);
}
}
}
appArtifact.setPaths(PathsCollection.of(projectFile.toPath()));
QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder()
.setAppArtifact(appArtifact)
.setMavenArtifactResolver(resolver)
.setBaseClassLoader(BuildMojo.class.getClassLoader())
.setBuildSystemProperties(realProperties)
.setLocalProjectDiscovery(false)
.setProjectRoot(project.getBasedir().toPath())
.setBaseName(finalName)
.setTargetDirectory(buildDir.toPath());
for (MavenProject project : project.getCollectedProjects()) {
builder.addLocalArtifact(new AppArtifactKey(project.getGroupId(), project.getArtifactId(), null,
project.getArtifact().getArtifactHandler().getExtension()));
}
try (CuratedApplication curatedApplication = builder
.build().bootstrap()) {
AugmentAction action = curatedApplication.createAugmentor();
AugmentResult result = action.createProductionApplication();
Artifact original = project.getArtifact();
if (result.getJar() != null) {
if (result.getJar().isUberJar() && result.getJar().getOriginalArtifact() != null) {
final Path standardJar = curatedApplication.getAppModel().getAppArtifact().getPaths().getSinglePath();
if (Files.exists(standardJar)) {
try {
Files.deleteIfExists(result.getJar().getOriginalArtifact());
Files.move(standardJar, result.getJar().getOriginalArtifact());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
original.setFile(result.getJar().getOriginalArtifact().toFile());
}
}
if (result.getJar().isUberJar()) {
projectHelper.attachArtifact(project, result.getJar().getPath().toFile(), "runner");
}
}
}
} catch (Exception e) {
throw new MojoExecutionException("Failed to build quarkus application", e);
} finally {
if (clear) {
System.clearProperty(QUARKUS_PACKAGE_UBER_JAR);
}
}
}

Line under review: File projectFile = projectArtifact.getFile();

Code after addressing the review:
public void execute() throws MojoExecutionException {
if (project.getPackaging().equals("pom")) {
getLog().info("Type of the artifact is POM, skipping build goal");
return;
}
if (skip) {
getLog().info("Skipping Quarkus build");
return;
}
boolean clear = false;
try {
final Properties projectProperties = project.getProperties();
final Properties realProperties = new Properties();
for (String name : projectProperties.stringPropertyNames()) {
if (name.startsWith("quarkus.")) {
realProperties.setProperty(name, projectProperties.getProperty(name));
}
}
if (uberJar && System.getProperty(QUARKUS_PACKAGE_UBER_JAR) == null) {
System.setProperty(QUARKUS_PACKAGE_UBER_JAR, "true");
clear = true;
}
realProperties.putIfAbsent("quarkus.application.name", project.getArtifactId());
realProperties.putIfAbsent("quarkus.application.version", project.getVersion());
MavenArtifactResolver resolver = MavenArtifactResolver.builder()
.setWorkspaceDiscovery(false)
.setRepositorySystem(repoSystem)
.setRepositorySystemSession(repoSession)
.setRemoteRepositories(repos)
.build();
final Artifact projectArtifact = project.getArtifact();
final AppArtifact appArtifact = new AppArtifact(projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
projectArtifact.getClassifier(), projectArtifact.getArtifactHandler().getExtension(),
projectArtifact.getVersion());
File projectFile = projectArtifact.getFile();
if (projectFile == null) {
projectFile = new File(project.getBuild().getOutputDirectory());
if (!projectFile.exists()) {
if (hasSources(project)) {
throw new MojoExecutionException("Project " + project.getArtifact() + " has not been compiled yet");
}
if (!projectFile.mkdirs()) {
throw new MojoExecutionException("Failed to create the output dir " + projectFile);
}
}
}
appArtifact.setPaths(PathsCollection.of(projectFile.toPath()));
QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder()
.setAppArtifact(appArtifact)
.setMavenArtifactResolver(resolver)
.setBaseClassLoader(BuildMojo.class.getClassLoader())
.setBuildSystemProperties(realProperties)
.setLocalProjectDiscovery(false)
.setProjectRoot(project.getBasedir().toPath())
.setBaseName(finalName)
.setTargetDirectory(buildDir.toPath());
for (MavenProject project : project.getCollectedProjects()) {
builder.addLocalArtifact(new AppArtifactKey(project.getGroupId(), project.getArtifactId(), null,
project.getArtifact().getArtifactHandler().getExtension()));
}
try (CuratedApplication curatedApplication = builder
.build().bootstrap()) {
AugmentAction action = curatedApplication.createAugmentor();
AugmentResult result = action.createProductionApplication();
Artifact original = project.getArtifact();
if (result.getJar() != null) {
if (result.getJar().isUberJar() && result.getJar().getOriginalArtifact() != null) {
final Path standardJar = curatedApplication.getAppModel().getAppArtifact().getPaths().getSinglePath();
if (Files.exists(standardJar)) {
try {
Files.deleteIfExists(result.getJar().getOriginalArtifact());
Files.move(standardJar, result.getJar().getOriginalArtifact());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
original.setFile(result.getJar().getOriginalArtifact().toFile());
}
}
if (result.getJar().isUberJar()) {
projectHelper.attachArtifact(project, result.getJar().getPath().toFile(), "runner");
}
}
}
} catch (Exception e) {
throw new MojoExecutionException("Failed to build quarkus application", e);
} finally {
if (clear) {
System.clearProperty(QUARKUS_PACKAGE_UBER_JAR);
}
}
}