Check parentArtifact version for robustness, and only when it is (recursively) is a vespa parent
package com.yahoo.container.plugin.mojo;
import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -56,20 +57,30 @@ public class ApplicationMojo extends AbstractMojo {
/** Writes meta data about this package if the destination directory exists. */
private void addBuildMetaData(File applicationDestination) throws MojoExecutionException {
- if ( ! applicationDestination.exists())
- return;
-
- // Compile version is the build version of the parent project, unless specifically set.
- MavenProject parent = project;
- while (parent.getParent() != null) parent = parent.getParent();
- Version parentVersion = Version.from(parent.getVersion());
- Version compileVersion = vespaversion == null ? parentVersion : Version.from(vespaversion);
+ if ( ! applicationDestination.exists()) return;
+
+ if (vespaversion == null)
+ vespaversion = project.getPlugin("com.yahoo.vespa:vespa-application-maven-plugin").getVersion();
+
+ Version compileVersion = Version.from(vespaversion);
+
+ MavenProject current = project;
+ while (current.getParent() != null && current.getParent().getParentArtifact() != null)
+ current = current.getParent();
+
+ boolean hasVespaParent = false;
+ Artifact parentArtifact = current.getParentArtifact();
+ if (parentArtifact != null && parentArtifact.getGroupId().startsWith("com.yahoo.vespa")) {
+ hasVespaParent = true;
+ Version parentVersion = Version.from(parentArtifact.getVersion());
if (parentVersion.compareTo(compileVersion) < 0)
throw new IllegalArgumentException("compile version (" + compileVersion + ") cannot be higher than parent version (" + parentVersion + ")");
+ }
- String metaData = String.format("{\"compileVersion\": \"%s\",\n \"buildTime\": %d}",
+ String metaData = String.format("{\n \"compileVersion\": \"%s\",\n \"buildTime\": %d,\n \"hasVespaParent\": %b\n}",
compileVersion,
- System.currentTimeMillis());
+ System.currentTimeMillis(),
+ hasVespaParent);
try {
Files.write(applicationDestination.toPath().resolve("build-meta.json"),
metaData.getBytes(StandardCharsets.UTF_8));
