@Override
    protected void doExecute() throws IOException {
        Path output = Paths.get(outputFile).toAbsolutePath();
        OptionalInt allowMajor = majorVersion(new File(project.getBasedir(), "src/main/application/deployment.xml").toPath());
        allowMajor.ifPresent(major -> getLog().info("Allowing only major version " + major + "."));

        Version compileVersion = Version.fromString(controller.compileVersion(id, allowMajor));

        MavenProject current = project;
        while (current.getParent() != null && current.getParent().getParentArtifact() != null)
            current = current.getParent();

        Version parentVersion;
        Artifact parentArtifact = current.getParentArtifact();
        if (parentArtifact != null && parentArtifact.getGroupId().matches("(com\\.yahoo\\.vespa|ai\\.vespa)(\\..+)?")) {
            parentVersion = Version.fromString(parentArtifact.getVersion());
            if (parentVersion.compareTo(compileVersion) < 0)
                throw new IllegalArgumentException("compile version (" + compileVersion + ") cannot be higher than parent version (" + parentVersion + ")");
        }

        getLog().info("Vespa version to compile against is '" + compileVersion.toFullString() + "'.");
        getLog().info("Writing compile version to '" + output + "'.");
        Files.createDirectories(output.getParent());
        Files.writeString(output, compileVersion.toFullString());
    }
Finds the Vespa version to compile against, for a hosted Vespa application.

@author jonmv
vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/CompileVersionMojo.java