diff --git a/src/main/java/com/widen/versioning/VersionGenerator.java b/src/main/java/com/widen/versioning/VersionGenerator.java index 9efcaf5..26f675f 100644 --- a/src/main/java/com/widen/versioning/VersionGenerator.java +++ b/src/main/java/com/widen/versioning/VersionGenerator.java @@ -60,11 +60,12 @@ public static String gitDescribe(Settings settings, File projectDir) { process.waitFor(); if (process.exitValue() != 0 || output.isEmpty()) { - return null; + throw new RuntimeException("Git returned status code " + process.exitValue() + ": " + output); } return output; - } catch (Exception e) { + } + catch (Exception e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/widen/versioning/VersioningPlugin.java b/src/main/java/com/widen/versioning/VersioningPlugin.java index b5cfee9..4aab246 100644 --- a/src/main/java/com/widen/versioning/VersioningPlugin.java +++ b/src/main/java/com/widen/versioning/VersioningPlugin.java @@ -16,14 +16,24 @@ public void apply(final Project project) { task.doLast(t -> System.out.println(project.getVersion())); // Defer setting the version until after the build script is evaluated. - project.afterEvaluate(p -> { - String version = VersionGenerator.generateFromGit(settings, p.getRootProject().getProjectDir()); - if (version != null) { - p.setVersion(version); - } - else if ("unspecified".equals(p.getVersion())) { - p.setVersion(settings.initialVersion); - } - }); + project.afterEvaluate(p -> applyVersion(project, settings)); + } + + private void applyVersion(final Project project, final Settings settings) { + String version = null; + try { + version = VersionGenerator.generateFromGit(settings, project.getRootProject().getProjectDir()); + } + catch (Exception e) { + project.getLogger().warn("Error trying to determine project version", e); + } + + if (version != null) { + project.setVersion(version); + } + else if ("unspecified".equals(project.getVersion())) { + project.getLogger().debug("No version specified, using initial version"); + project.setVersion(settings.initialVersion); + } } }