From 1c45754eb08f767d2f144234fce232ae8e1843d0 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 12 Aug 2022 10:51:52 -0400 Subject: [PATCH] Add a `dependencyManagement` section if missing --- .../maven/plugins/hpi/TestDependencyMojo.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jenkinsci/maven/plugins/hpi/TestDependencyMojo.java b/src/main/java/org/jenkinsci/maven/plugins/hpi/TestDependencyMojo.java index 29ee3ec44d..10890b63d2 100644 --- a/src/main/java/org/jenkinsci/maven/plugins/hpi/TestDependencyMojo.java +++ b/src/main/java/org/jenkinsci/maven/plugins/hpi/TestDependencyMojo.java @@ -579,12 +579,12 @@ private static void applyOverrides( throw new MojoExecutionException("Cannot add self to dependency management section"); } DependencyManagement dm = project.getDependencyManagement(); - if (dm != null) { - log.info(String.format("Adding dependency management entry %s:%s", key, dependency.getVersion())); - dm.addDependency(dependency); - } else { - throw new MojoExecutionException(String.format("Failed to add dependency management entry %s:%s because the project does not have a dependency management section", key, overrides.get(key))); + if (dm == null) { + dm = new DependencyManagement(); + project.getModel().setDependencyManagement(dm); } + log.info(String.format("Adding dependency management entry %s:%s", key, dependency.getVersion())); + dm.addDependency(dependency); overrideAdditions.add(key); } } else {