You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2023/07/04 18:15:21 UTC

[sling-maven-enforcer-rules] branch feature/update-to-3.2.1-enforcer-api created (now eed0049)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a change to branch feature/update-to-3.2.1-enforcer-api
in repository https://gitbox.apache.org/repos/asf/sling-maven-enforcer-rules.git


      at eed0049  SLING-11927 Update Enforcer API to 3.2.1+

This branch includes the following new commits:

     new eed0049  SLING-11927 Update Enforcer API to 3.2.1+

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-maven-enforcer-rules] 01/01: SLING-11927 Update Enforcer API to 3.2.1+

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/update-to-3.2.1-enforcer-api
in repository https://gitbox.apache.org/repos/asf/sling-maven-enforcer-rules.git

commit eed0049a1865ab350ad04057fcc638af6b27a80a
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Jul 4 20:15:16 2023 +0200

    SLING-11927 Update Enforcer API to 3.2.1+
    
    Get rid of rule requireExplicitDependencyScope now being part of
    enforcer standard rules
---
 README.md                                          |  52 +----------
 pom.xml                                            |  19 +---
 src/it/require-dependency-scope/invoker.properties |  18 ----
 src/it/require-dependency-scope/pom.xml            |  87 ------------------
 src/it/require-dependency-scope/verify.groovy      |  22 -----
 .../pom.xml                                        |   2 +-
 .../verify.groovy                                  |   6 +-
 .../enforcer/RequireExplicitDependencyScope.java   |  95 --------------------
 ...uireProvidedDependenciesInRuntimeClasspath.java | 100 +++++++++------------
 9 files changed, 51 insertions(+), 350 deletions(-)

diff --git a/README.md b/README.md
index 29b503d..7a1a56a 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ It provides additional [Maven Enforcer](https://maven.apache.org/enforcer/maven-
 
 ## Rules
 
-**Prerequisites:** `maven-enforcer-plugin` 3.0.0 or newer
+**Prerequisites:** `maven-enforcer-plugin` 3.2.1 or newer
 
 ### Require Provided Dependencies in Runtime Classpath (since version 1.0.0)
 
@@ -64,7 +64,7 @@ All parameters are optional.
             </goals>
             <configuration>
               <rules>
-                <requireProvidedDependenciesInRuntimeClasspath implementation="org.apache.sling.maven.enforcer.RequireProvidedDependenciesInRuntimeClasspath">
+                <requireProvidedDependenciesInRuntimeClasspath>
                   <excludes>
                     <exclude>javax.servlet:javax.servlet-api</exclude>
                   </excludes>
@@ -80,50 +80,6 @@ All parameters are optional.
 </project>
 ```
 
-### Require Explicit Dependency Scope (since version 1.1.0)
+### Require Explicit Dependency Scope (no longer available since 1.2.0)
 
-Checks that all dependencies have an explicitly declared scope in the non-effective pom (i.e. without taking inheritance or dependency management into account). Useful when the scope is no longer part of the `dependencyManagement` or in general to force making developers a distinct decision (e.g. prevents the default scope compile being used for test dependencies by accident).
-
-*This rule is part of `maven-enforcer-plugin` since version 3.2.1 ([MENFORCER-423](https://issues.apache.org/jira/browse/MENFORCER-423)), so should no longer be used from this module.*
-
-#### Parameters
-
-This rule does not support any parameters.
-
-#### Sample Plugin Configuration:
-
-```
-<project>
-  [...]
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-enforcer-plugin</artifactId>
-        <version>3.0.0</version>
-        <dependencies>
-          <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>maven-enforcer-rules</artifactId>
-            <version>LATEST</version>
-          </dependency>
-        </dependencies>
-        <executions>
-          <execution>
-            <id>require-explicit-dependency-scope</id>
-            <goals>
-              <goal>enforce</goal>
-            </goals>
-            <configuration>
-              <rules>
-                <requireExplicitDependencyScope implementation="org.apache.sling.maven.enforcer.RequireExplicitDependencyScope" />
-              </rules>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-  [...]
-</project>
-```
\ No newline at end of file
+*This rule is part of `maven-enforcer-plugin` since version 3.2.1 ([MENFORCER-423](https://issues.apache.org/jira/browse/MENFORCER-423)), and therefore was removed from this module.*
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index be978db..030e5be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>48</version>
+        <version>49</version>
     </parent>
     <artifactId>maven-enforcer-rules</artifactId>
     <version>1.1.1-SNAPSHOT</version>
@@ -39,8 +39,8 @@
 
     <properties>
         <sling.java.version>8</sling.java.version>
-        <api.version>3.0.0</api.version>
-        <maven.version>3.1.1</maven.version><!-- must be the same version as used by m-enforcer-p/enforcer-api due to shared classloader -->
+        <api.version>3.2.1</api.version>
+        <maven.version>3.2.5</maven.version><!-- must be the same version as used by m-enforcer-p/enforcer-api due to shared classloader -->
         <project.build.outputTimestamp>1656073064</project.build.outputTimestamp>
     </properties>
 
@@ -64,18 +64,6 @@
             <version>${api.version}</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.maven.enforcer</groupId>
-            <artifactId>enforcer-rules</artifactId>
-            <version>${api.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>*</groupId>
-                    <artifactId>*</artifactId>
-                </exclusion>
-            </exclusions>
-            <scope>provided</scope>
-        </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-core</artifactId>
@@ -114,7 +102,6 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-invoker-plugin</artifactId>
-                <version>3.3.0</version>
                 <configuration>
                     <projectsDirectory>src/it</projectsDirectory>
                     <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
diff --git a/src/it/require-dependency-scope/invoker.properties b/src/it/require-dependency-scope/invoker.properties
deleted file mode 100644
index c19c711..0000000
--- a/src/it/require-dependency-scope/invoker.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-# 
-#   http://www.apache.org/licenses/LICENSE-2.0
-# 
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-invoker.buildResult = failure
\ No newline at end of file
diff --git a/src/it/require-dependency-scope/pom.xml b/src/it/require-dependency-scope/pom.xml
deleted file mode 100644
index a6b4d51..0000000
--- a/src/it/require-dependency-scope/pom.xml
+++ /dev/null
@@ -1,87 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements. See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership. The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License. You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied. See the License for the
-    specific language governing permissions and limitations
-    under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>org.apache.sling.maven.enforcer.it</groupId>
-    <artifactId>require-explicit-dependency-scope</artifactId>
-    <packaging>pom</packaging>
-    <version>@project.version@</version>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-enforcer-plugin</artifactId>
-                <version>3.0.0</version>
-                <dependencies>
-                    <dependency>
-                        <groupId>@project.groupId@</groupId>
-                        <artifactId>@project.artifactId@</artifactId>
-                        <version>@project.version@</version>
-                    </dependency>
-                </dependencies>
-                <executions>
-                    <execution>
-                        <id>require-dependency-scope</id>
-                        <goals>
-                            <goal>enforce</goal>
-                        </goals>
-                        <configuration>
-                            <rules>
-                                <requireExplicitDependencyScope
-                                    implementation="org.apache.sling.maven.enforcer.RequireExplicitDependencyScope" />
-                            </rules>
-                            <fail>true</fail>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-    
-   <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.apache.jackrabbit.vault</groupId>
-                <artifactId>vault-cli</artifactId>
-                <version>3.6.0</version>
-                <scope>provided</scope>
-            </dependency>
-        </dependencies>
-   </dependencyManagement>
-    <dependencies>
-        <!-- missing explicit scope -->
-        <dependency>
-            <groupId>org.apache.jackrabbit.vault</groupId>
-            <artifactId>vault-cli</artifactId>
-        </dependency>
-
-        <!-- test scope -->
-        <dependency>
-            <groupId>org.hamcrest</groupId>
-            <artifactId>hamcrest</artifactId>
-            <version>2.2</version>
-            <scope>test</scope>
-        </dependency>
-
-    </dependencies>
-</project>
\ No newline at end of file
diff --git a/src/it/require-dependency-scope/verify.groovy b/src/it/require-dependency-scope/verify.groovy
deleted file mode 100644
index dbcbdb3..0000000
--- a/src/it/require-dependency-scope/verify.groovy
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-File buildLog = new File(basedir, 'build.log')
-assert buildLog.text.contains('Found 1 missing dependency scope. Look at the warnings emitted above for the details.')
-assert buildLog.text.contains('[WARNING] Dependency org.apache.jackrabbit.vault:vault-cli:jar @ line 73, column 21 does not have an explicit scope defined!')
-assert true
\ No newline at end of file
diff --git a/src/it/require-provided-deps-in-runtime-classpath/pom.xml b/src/it/require-provided-deps-in-runtime-classpath/pom.xml
index de5d56d..d775398 100644
--- a/src/it/require-provided-deps-in-runtime-classpath/pom.xml
+++ b/src/it/require-provided-deps-in-runtime-classpath/pom.xml
@@ -31,7 +31,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-enforcer-plugin</artifactId>
-                <version>3.0.0</version>
+                <version>3.2.1</version>
                 <dependencies>
                     <dependency>
                         <groupId>@project.groupId@</groupId>
diff --git a/src/it/require-provided-deps-in-runtime-classpath/verify.groovy b/src/it/require-provided-deps-in-runtime-classpath/verify.groovy
index 14cfcf9..6e5e883 100644
--- a/src/it/require-provided-deps-in-runtime-classpath/verify.groovy
+++ b/src/it/require-provided-deps-in-runtime-classpath/verify.groovy
@@ -18,7 +18,7 @@
  */
 File buildLog = new File(basedir, 'build.log')
 assert buildLog.text.contains('Found 17 missing runtime dependencies')
-assert buildLog.text.contains('[WARNING] Dependency org.osgi:org.osgi.framework:jar:1.8.0 (provided) via org.apache.jackrabbit.vault:vault-cli:jar:3.6.0 -> org.apache.jackrabbit.vault:org.apache.jackrabbit.vault:jar:3.6.0 not found as runtime dependency!')
-assert buildLog.text.contains('[WARNING] Dependency com.google.code.findbugs:jsr305:jar:3.0.2 (provided) not found as runtime dependency!')
-assert buildLog.text.contains('[WARNING] Found provided dependency org.apache.jackrabbit:oak-jackrabbit-api:jar:1.42.0 only with potentially incompatible version 1.40.0 in runtime classpath')
+assert buildLog.text.contains('[ERROR] Dependency org.osgi:org.osgi.framework:jar:1.8.0 (provided) via org.apache.jackrabbit.vault:vault-cli:jar:3.6.0 -> org.apache.jackrabbit.vault:org.apache.jackrabbit.vault:jar:3.6.0 not found as runtime dependency!')
+assert buildLog.text.contains('[ERROR] Dependency com.google.code.findbugs:jsr305:jar:3.0.2 (provided) not found as runtime dependency!')
+assert buildLog.text.contains('[ERROR] Found provided dependency org.apache.jackrabbit:oak-jackrabbit-api:jar:1.42.0 only with potentially incompatible version 1.40.0 in runtime classpath')
 assert true
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java b/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java
deleted file mode 100644
index 58db245..0000000
--- a/src/main/java/org/apache/sling/maven/enforcer/RequireExplicitDependencyScope.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package org.apache.sling.maven.enforcer;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import java.text.ChoiceFormat;
-import java.util.List;
-
-import javax.annotation.Nonnull;
-
-import org.apache.maven.enforcer.rule.api.EnforcerRule2;
-import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
-import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.InputLocation;
-import org.apache.maven.plugins.enforcer.AbstractNonCacheableEnforcerRule;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.utils.logging.MessageBuilder;
-import org.apache.maven.shared.utils.logging.MessageUtils;
-import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
-
-/** 
- * Checks that all dependencies have an explicitly declared scope in the non-effective pom (i.e. without taking inheritance or dependency management into account)/
- */
-public class RequireExplicitDependencyScope extends AbstractNonCacheableEnforcerRule implements EnforcerRule2 {
-
-    @Override
-    public void execute(@Nonnull EnforcerRuleHelper helper) throws EnforcerRuleException {
-        try {
-            int numMissingDependencyScopes = 0;
-            MavenProject project = (MavenProject) helper.evaluate("${project}");
-            if (project == null) {
-                throw new ExpressionEvaluationException("${project} is null");
-            }
-            List<Dependency> dependencies = project.getOriginalModel().getDependencies(); // this is the non-effective model but the original one without inheritance and interpolation resolved
-            // check scope without considering inheritance
-            for (Dependency dependency : dependencies) {
-                helper.getLog().debug("Found dependency " + dependency);
-                if (dependency.getScope() == null) {
-                    MessageBuilder msgBuilder = MessageUtils.buffer();
-                    helper.getLog().warn(msgBuilder.a("Dependency ").strong(dependency.getManagementKey()).a(" @ ").strong(formatLocation(dependency.getLocation(""))).a(" does not have an explicit scope defined!").toString());
-                    numMissingDependencyScopes++;
-                }
-            }
-            if (numMissingDependencyScopes > 0) {
-                ChoiceFormat scopesFormat = new ChoiceFormat("1#scope|1<scopes");
-                throw new EnforcerRuleException("Found " + numMissingDependencyScopes + " missing dependency " + scopesFormat.format(numMissingDependencyScopes) + ". Look at the warnings emitted above for the details.");
-            }
-        } catch (ExpressionEvaluationException eee) {
-            throw new EnforcerRuleException("Cannot resolve expression: " + eee.getCause(), eee);
-        }
-    }
-
-    /**
-     * Creates a string with line/column information for problems originating directly from this POM.
-     * Inspired by <a href="https://github.com/apache/maven/blob/d82ab09ae106131609efb8b98b67dae17b0780d0/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java#L136-L173">ModelProblemUtils.formatLocation(...)</a>
-     *
-     * @param location The location which should be formatted, must not be {@code null}.
-     * @return The formatted problem location or an empty string if unknown, never {@code null}.
-     */
-    protected static String formatLocation(InputLocation location) {
-        StringBuilder buffer = new StringBuilder();
-        if (location.getLineNumber() > 0) {
-            if (buffer.length() > 0) {
-                buffer.append( ", " );
-            }
-            buffer.append("line ").append(location.getLineNumber());
-        }
-        if (location.getColumnNumber() > 0) {
-            if (buffer.length() > 0) {
-                buffer.append( ", " );
-            }
-            buffer.append("column ").append(location.getColumnNumber());
-        }
-        return buffer.toString();
-    }
-
-}
diff --git a/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java b/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java
index 34d5a9c..c49bb94 100644
--- a/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java
+++ b/src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java
@@ -31,23 +31,21 @@ import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
-import javax.annotation.Nonnull;
+import javax.inject.Inject;
+import javax.inject.Named;
 
 import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.enforcer.rule.api.EnforcerRule2;
+import org.apache.maven.enforcer.rule.api.AbstractEnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerLogger;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
-import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.plugins.enforcer.AbstractNonCacheableEnforcerRule;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.utils.logging.MessageBuilder;
 import org.apache.maven.shared.utils.logging.MessageUtils;
-import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.RepositorySystemSession;
@@ -77,8 +75,8 @@ import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor;
  * 
  * This check is useful to make sure that a Maven Plugin has access to all necessary classes at run time. 
  */
-public class RequireProvidedDependenciesInRuntimeClasspath
-        extends AbstractNonCacheableEnforcerRule implements EnforcerRule2 {
+@Named("requireProvidedDependenciesInRuntimeClasspath")
+public class RequireProvidedDependenciesInRuntimeClasspath extends AbstractEnforcerRule {
 
     /** 
      * Specify the banned dependencies. This is a list of artifacts in format {@code <groupId>[:<artifactId>[:<extension>[:<classifier>]]]}. 
@@ -101,33 +99,19 @@ public class RequireProvidedDependenciesInRuntimeClasspath
      */
     private boolean includeDirects = false;
 
-    @SuppressWarnings("unchecked")
+    @Inject
+    private MavenProject project;
+    
+    @Inject
+    private MavenSession session;
+
+    @Inject
+    private RepositorySystem repoSystem;
+
     @Override
-    public void execute(@Nonnull EnforcerRuleHelper helper) throws EnforcerRuleException {
-        MavenProject project;
-        DefaultRepositorySystemSession newRepoSession;
-        RepositorySystem repoSystem;
-        List<RemoteRepository> remoteRepositories;
-        try {
-            project = (MavenProject) helper.evaluate("${project}");
-            if (project == null) {
-                throw new ExpressionEvaluationException("${project} is null");
-            }
-            RepositorySystemSession repoSession = (RepositorySystemSession) helper.evaluate("${repositorySystemSession}");
-            if (repoSession == null) {
-                throw new ExpressionEvaluationException("${repositorySystemSession} is null");
-            }
-            // get a new session to be able to tweak the dependency selector
-            newRepoSession = new DefaultRepositorySystemSession(repoSession);
-            remoteRepositories = (List<RemoteRepository>) helper.evaluate("${project.remoteProjectRepositories}");
-            repoSystem = helper.getComponent(RepositorySystem.class);
-        } catch (ExpressionEvaluationException eee) {
-            throw new EnforcerRuleException("Cannot resolve expression: " + eee.getCause(), eee);
-        } catch (ComponentLookupException cle) {
-            throw new EnforcerRuleException("Unable to retrieve component RepositorySystem", cle);
-        }
-        Log log = helper.getLog();
-        
+    public void execute() throws EnforcerRuleException {
+        // get a new session to be able to tweak the dependency selector
+        DefaultRepositorySystemSession newRepoSession = new DefaultRepositorySystemSession(session.getRepositorySession());
         Collection<DependencySelector> depSelectors = new ArrayList<>();
         depSelectors.add(new ScopeDependencySelector("test")); // exclude transitive and direct "test" dependencies of the rootDependency (i.e. the current project)
         // add also the exclude patterns
@@ -147,18 +131,17 @@ public class RequireProvidedDependenciesInRuntimeClasspath
         // use the ones for https://maven.apache.org/guides/mini/guide-maven-classloading.html#3-plugin-classloaders
         @SuppressWarnings("deprecation")
         List<org.eclipse.aether.artifact.Artifact> runtimeArtifacts = project.getRuntimeArtifacts().stream().map(RepositoryUtils::toArtifact).collect(Collectors.toList());
-        if (log.isDebugEnabled()) {
-            log.debug("Collected " + runtimeArtifacts.size()+ " runtime dependencies ");
-            for (Artifact runtimeArtifact : runtimeArtifacts) {
-                log.debug(runtimeArtifact.toString());
-            }
+        // no guard supported here due to https://issues.apache.org/jira/browse/MENFORCER-488
+        getLog().debug("Collected " + runtimeArtifacts.size()+ " runtime dependencies ");
+        for (Artifact runtimeArtifact : runtimeArtifacts) {
+            getLog().debug(runtimeArtifact.toString());
         }
 
         Dependency rootDependency = RepositoryUtils.toDependency(project.getArtifact(), null);
         try {
             DependencyNode rootDependencyNode = collectTransitiveDependencies(
-                    rootDependency, repoSystem, newRepoSession, remoteRepositories, log);
-            int numViolations = checkForMissingArtifacts(rootDependencyNode, runtimeArtifacts, log);
+                    rootDependency, repoSystem, newRepoSession, project.getRemoteProjectRepositories());
+            int numViolations = checkForMissingArtifacts(rootDependencyNode, runtimeArtifacts);
             if (numViolations > 0) {
                 ChoiceFormat dependenciesFormat = new ChoiceFormat("1#dependency|1<dependencies");
                 throw new EnforcerRuleException("Found " + numViolations + " missing runtime " + dependenciesFormat.format(numViolations) + ". Look at the warnings emitted above for the details.");
@@ -267,12 +250,12 @@ public class RequireProvidedDependenciesInRuntimeClasspath
 
     private static final class MissingArtifactsDependencyVisitor implements DependencyVisitor {
         private final List<Artifact> artifacts;
-        private final Log log;
+        private final EnforcerLogger log;
         private int numMissingArtifacts;
         private final Deque<DependencyNode> nodeStack; // all intermediate nodes (without the root node)
         private boolean isRoot;
 
-        MissingArtifactsDependencyVisitor(List<Artifact> artifacts, Log log) {
+        MissingArtifactsDependencyVisitor(List<Artifact> artifacts, EnforcerLogger log) {
             this.artifacts = artifacts;
             this.log = log;
             numMissingArtifacts = 0;
@@ -288,11 +271,11 @@ public class RequireProvidedDependenciesInRuntimeClasspath
                 try {
                     if (!isCompatibleArtifactContainedInList(dependencyNode.getArtifact(), artifacts, log)) {
                         MessageBuilder msgBuilder = MessageUtils.buffer();
-                        log.warn(msgBuilder.a("Dependency ").strong(dependencyNode.getDependency()).mojo(dumpIntermediatePath(nodeStack)).a(" not found as runtime dependency!").toString());
+                        log.warnOrError(msgBuilder.a("Dependency ").strong(dependencyNode.getDependency()).mojo(dumpIntermediatePath(nodeStack)).a(" not found as runtime dependency!").toString());
                         numMissingArtifacts++;
                     }
                 } catch (InvalidVersionSpecificationException e) {
-                    log.error("Invalid version given for artifact " + dependencyNode.getArtifact(), e);
+                    log.error("Invalid version given for artifact " + dependencyNode.getArtifact() + ": " + e.getCause());
                 }
                 nodeStack.addLast(dependencyNode);
             }
@@ -324,30 +307,27 @@ public class RequireProvidedDependenciesInRuntimeClasspath
     protected DependencyNode collectTransitiveDependencies(
             org.eclipse.aether.graph.Dependency rootDependency,
             RepositorySystem repoSystem, RepositorySystemSession repoSession,
-            List<RemoteRepository> remoteRepositories, Log log)
+            List<RemoteRepository> remoteRepositories)
             throws DependencyCollectionException {
         CollectRequest collectRequest = new CollectRequest(rootDependency, remoteRepositories);
         CollectResult collectResult = repoSystem.collectDependencies(repoSession, collectRequest);
-        if (log.isDebugEnabled()) {
-            // draw full dependency graph
-            StringWriter writer = new StringWriter();
-            DependencyVisitor depVisitor = new TreeDependencyVisitor(
-                    new DependencyVisitorPrinter(new PrintWriter(writer)));
-            collectResult.getRoot().accept(depVisitor);
-            log.debug("dependency tree: " + writer.toString());
-        }
+        // draw full dependency graph
+        StringWriter writer = new StringWriter();
+        DependencyVisitor depVisitor = new TreeDependencyVisitor(
+                new DependencyVisitorPrinter(new PrintWriter(writer)));
+        collectResult.getRoot().accept(depVisitor);
+        getLog().debug("dependency tree: " + writer.toString());
         return collectResult.getRoot();
     }
 
-    protected int checkForMissingArtifacts(DependencyNode rootDependencyNode, List<Artifact> runtimeArtifacts,
-            Log log) {
-        MissingArtifactsDependencyVisitor depVisitor = new MissingArtifactsDependencyVisitor(runtimeArtifacts, log);
+    protected int checkForMissingArtifacts(DependencyNode rootDependencyNode, List<Artifact> runtimeArtifacts) {
+        MissingArtifactsDependencyVisitor depVisitor = new MissingArtifactsDependencyVisitor(runtimeArtifacts, getLog());
         rootDependencyNode.accept(depVisitor);
         return depVisitor.getNumMissingArtifacts();
     }
 
     protected static boolean isCompatibleArtifactContainedInList(Artifact artifact,
-            List<Artifact> artifacts, Log log) throws InvalidVersionSpecificationException {
+            List<Artifact> artifacts, EnforcerLogger log) throws InvalidVersionSpecificationException {
         for (Artifact artifactInList : artifacts) {
             if (areArtifactsEqualDisregardingVersion(artifact, artifactInList)) {
                 // check version compatibility
@@ -355,7 +335,7 @@ public class RequireProvidedDependenciesInRuntimeClasspath
                     return true;
                 } else {
                     MessageBuilder msgBuilder = MessageUtils.buffer();
-                    log.warn("Found provided dependency " + msgBuilder.strong(artifact).a(" only with potentially incompatible version ").strong(artifactInList.getVersion()).toString() + " in runtime classpath");
+                    log.warnOrError("Found provided dependency " + msgBuilder.strong(artifact).a(" only with potentially incompatible version ").strong(artifactInList.getVersion()).toString() + " in runtime classpath");
                 }
             }
         }