diff --git a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java index 695f1139..24c2545c 100644 --- a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java +++ b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java @@ -173,7 +173,10 @@ public void setRulesToExecute(List rulesToExecute) throws MojoExecutionE @Parameter(required = false, property = "rules") @Deprecated public void setCommandLineRules(List rulesToExecute) throws MojoExecutionException { - getLog().warn("Detected the usage of property '-Drules' which is deprecated. Use '-Denforcer.rules' instead."); + if (rulesToExecute != null && !rulesToExecute.isEmpty()) { + getLog().warn( + "Detected the usage of property '-Drules' which is deprecated. Use '-Denforcer.rules' instead."); + } setRulesToExecute(rulesToExecute); } diff --git a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java index 4be12c43..cd25b7c3 100644 --- a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java +++ b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java @@ -319,6 +319,17 @@ void testShouldPrintWarnWhenUsingDeprecatedRulesProperty() throws MojoExecutionE .warn("Detected the usage of property '-Drules' which is deprecated. Use '-Denforcer.rules' instead."); } + @Test + void testShouldNotPrintWarnWhenDeprecatedRulesPropertyIsEmpty() throws MojoExecutionException { + setupBasics(false); + + Log logSpy = setupLogSpy(); + + mojo.setCommandLineRules(Collections.emptyList()); + + Mockito.verifyNoInteractions(logSpy); + } + private void setupBasics(boolean fail) { mojo.setFail(fail); mojo.setSession(EnforcerTestUtils.getMavenSession());