### Invalid parent configuration example Source: https://maven.apache.org/enforcer/enforcer-rules/reactorModuleConvergence.html Example of a parent configuration where the parent does not belong to the current reactor. ```xml 1. 2. org.apache.enforcer 3. something-different 4. 1.1 5. 6. 7. module1 8. (..) ``` -------------------------------- ### getIncludes() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rules/dependency/BannedDependencies.html Gets the list of allowed dependencies. ```APIDOC ## getIncludes() ### Description Gets the includes. ### Method public List getIncludes() ### Returns - **List** - the includes ``` -------------------------------- ### Configure rules parameter Source: https://maven.apache.org/enforcer/maven-enforcer-plugin/enforce-mojo.html Example XML configuration for the rules parameter, showing how to define rules and their specific configurations. ```xml message for rule ``` -------------------------------- ### Example Mirror Configuration in settings.xml Source: https://maven.apache.org/enforcer/enforcer-rules/bannedRepositories.html Shows a mirror configuration in settings.xml that may affect how the BannedRepositories rule detects repositories. ```xml 1. 2. 3. nexus 4. * 5. http://.../nexus/.. 6. 7. ``` -------------------------------- ### Incorrect inter-module dependency version example Source: https://maven.apache.org/enforcer/enforcer-rules/reactorModuleConvergence.html Example of a POM configuration where a dependency references an incorrect version, causing a convergence failure. ```xml 1. 2. ... 3. ... 4. 1.2-SNAPSHOT 5. 6. 7. module1 8. 9. 10. 11. com.mycompany.project 12. myproject 13. 1.1 14. 15. (..) 16. 17. (..) ``` -------------------------------- ### Example Rules Configuration XML Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rule/api/AbstractEnforcerRuleConfigProvider.html The structure required for the configuration returned by the getRulesConfig method. ```xml config value ``` -------------------------------- ### getIncludes() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rules/dependency/RequireReleaseDeps.html Gets the list of included dependencies. ```APIDOC ## getIncludes() ### Description Gets the list of included dependencies. ### Method List getIncludes() ### Parameters None ### Returns List - the list of included dependencies ``` -------------------------------- ### External rules XML example Source: https://maven.apache.org/enforcer/enforcer-rules/apidocs/src-html/org/apache/maven/enforcer/rules/ExternalRules.html Example rule set that the 'location' parameter can point to. It bans two dependencies: com.google.code.findbugs:jsr305 and com.google.guava:listenablefuture. ```xml com.google.code.findbugs:jsr305 com.google.guava:listenablefuture ``` -------------------------------- ### Configure banDynamicVersions in maven-enforcer-plugin Source: https://maven.apache.org/enforcer/enforcer-rules/banDynamicVersions.html Example configuration for the banDynamicVersions rule within the maven-enforcer-plugin, demonstrating how to use the ignores list and allowSnapshots parameter. ```xml 1. 2. [...] 3. 4. 5. 6. org.apache.maven.plugins 7. maven-enforcer-plugin 8. 3.6.3 9. 10. 11. ban-dynamic-versions 12. 13. enforce 14. 15. 16. 17. 18. 19. org.apache.maven 20. 21. true 22. 23. 24. 25. 26. 27. 28. 29. 30. [...] 31. ``` -------------------------------- ### Maven Plugin Configuration for requireTextFileChecksum Source: https://maven.apache.org/enforcer/enforcer-rules/requireTextFileChecksum.html Example configuration for the maven-enforcer-plugin demonstrating multiple file checksum validations using different algorithms and settings. ```xml 1. 2. [...] 3. 4. 5. 6. org.apache.maven.plugins 7. maven-enforcer-plugin 8. 3.6.3 9. 10. 11. enforce-checksum 12. 13. enforce 14. 15. 16. 17. 18. ${project.build.outputDirectory}/foo.txt 19. d41d8cd98f00b204e9800998ecf8427e 20. md5 21. 22. 23. ${project.build.outputDirectory}/bar.txt 24. da39a3ee5e6b4b0d3255bfef95601890afd80709 25. sha1 26. UTF-8 27. 28. 29. ${project.build.outputDirectory}/baz.txt 30. e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 31. sha256 32. WINDOWS 33. 34. 35. ${project.build.outputDirectory}/qux.txt 36. 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b 37. sha384 38. 39. 40. ${project.build.outputDirectory}/quux.txt 41. cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e 42. sha512 43. 44. 45. true 46. 47. 48. 49. 50. 51. 52. [...] 53. ``` -------------------------------- ### Incorrect parent version configuration Source: https://maven.apache.org/enforcer/enforcer-rules/reactorModuleConvergence.html Example where a child module references a parent with an incorrect version. ```xml 1. 2. ... 3. ... 4. 1.1-SNAPSHOT 5. 6. 7. module1 8. 1.0-SNAPSHOT 9. (..) ``` -------------------------------- ### Configure requireFilesSize in Maven Enforcer Plugin Source: https://maven.apache.org/enforcer/enforcer-rules/requireFilesSize.html Example configuration for the maven-enforcer-plugin demonstrating how to enforce size constraints on specific files and directories. ```xml 1. 2. [...] 3. 4. 5. 6. org.apache.maven.plugins 7. maven-enforcer-plugin 8. 3.6.3 9. 10. 11. enforce-file-size 12. 13. enforce 14. 15. 16. 17. 18. 10000 19. 90 20. 21. ${project.build.outputDirectory}/foo.txt 22. ${project.build.outputDirectory}/foo2.txt 23. 24. 25. 26. 500000 27. true 28. 29. ${project.build.directory} 30. 31. 32. 33. true 34. 35. 36. 37. 38. 39. 40. [...] 41. ``` -------------------------------- ### Accidental parent version change configuration Source: https://maven.apache.org/enforcer/enforcer-rules/reactorModuleConvergence.html Example of a configuration where the parent version was changed accidentally. ```xml 1. 2. ... 3. ... 4. 1.1-SNAPSHOT 5. 6. 7. module1 8. (..) ``` -------------------------------- ### Configure requireSameVersions in Maven Enforcer Plugin Source: https://maven.apache.org/enforcer/enforcer-rules/requireSameVersions.html Example configuration showing how to enforce version consistency for plugins and dependencies within the maven-enforcer-plugin. ```xml 1. 2. [...] 3. 4. 5. 6. org.apache.maven.plugins 7. maven-enforcer-plugin 8. 3.6.3 9. 10. 11. enforce-no-snapshots 12. 13. enforce 14. 15. 16. 17. 18. 19. org.apache.maven.plugins:maven-surefire-plugin 20. org.apache.maven.plugins:maven-failsafe-plugin 21. org.apache.maven.plugins:maven-surefire-report-plugin 22. 23. 24. 25. 26. org.apache.maven 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. [...] 37. ``` -------------------------------- ### Configure requireJavaVendor in maven-enforcer-plugin Source: https://maven.apache.org/enforcer/enforcer-rules/requireJavaVendor.html Example configuration for the maven-enforcer-plugin showing how to define excludes and includes for Java vendors within the project build section. ```xml 1. 2. [...] 3. 4. 5. 6. org.apache.maven.plugins 7. maven-enforcer-plugin 8. 3.6.3 9. 10. 11. enforce-java 12. 13. enforce 14. 15. 16. 17. 18. 19. Pivotal 20. Oracle JDK 21. 22. 23. AdoptOpenJDK 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. [...] 34. ``` -------------------------------- ### Configure requirePrerequisite in Maven POM Source: https://maven.apache.org/enforcer/enforcer-rules/requirePrerequisite.html This example demonstrates how to configure the requirePrerequisite rule within the maven-enforcer-plugin. It shows both a specific version requirement and a version range notation. ```xml 1. 2. [...] 3. 4. 5. 6. org.apache.maven.plugins 7. maven-enforcer-plugin 8. 3.6.3 9. 10. 11. enforce-prerequisites 12. 13. enforce 14. 15. 16. 17. 18. 2.2.1 19. 20. 21. 22. [2.2.1,) 23. 24. 25. 26. 27. 28. 29. 30. 31. [...] 32. ``` -------------------------------- ### Maven project setup for requireUpperBoundDeps rule Source: https://maven.apache.org/enforcer/enforcer-rules/requireUpperBoundDeps.html This is the recommended Maven project configuration to enable the requireUpperBoundDeps rule using the maven-enforcer-plugin version 3.6.3. It includes commented examples for setting uniqueVersions, excludes, includes, and excludedScopes parameters. ```xml ... ... org.apache.maven.plugins maven-enforcer-plugin 3.6.3 enforce enforce ... ... ``` -------------------------------- ### Display current OS information with mvn --version Source: https://maven.apache.org/enforcer/enforcer-rules/requireOS.html Command to display the current OS information, including name, version, arch, and family. The output shows an example for macOS. ```bash mvn --version Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29) Maven home: /usr/local/Cellar/maven/3.8.7/libexec Java version: 1.8.0_352, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk@8/1.8.0+352/libexec/openjdk.jdk/Contents/Home/jre Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "12.6.1", arch: "x86_64", family: "mac" ``` -------------------------------- ### Verify PGP signatures with GPG Source: https://maven.apache.org/enforcer/guides/guides/guides/guides/guides/download.html Import the KEYS file and verify the signature of the downloaded file using GPG. ```bash % gpg --import KEYS % gpg --verify downloaded_file.asc downloaded_file ``` -------------------------------- ### XSLT transformation example Source: https://maven.apache.org/enforcer/enforcer-rules/apidocs/src-html/org/apache/maven/enforcer/rules/ExternalRules.html Example XSLT transformation that the 'xsltLocation' parameter can point to. It copies all nodes and removes any 'exclude' element containing 'com.google.code.findbugs:jsr305'. ```xml ``` -------------------------------- ### Verify PGP signatures using pgp Source: https://maven.apache.org/enforcer/guides/download.html Use pgp to add the KEYS file and verify the signature of the downloaded file. ```bash % pgp -ka KEYS % pgp downloaded_file.asc ``` -------------------------------- ### getVersion() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rules/version/RequireMavenVersion.html Gets the required version. ```APIDOC ## getVersion() ### Description Gets the required version. ### Method `public final String getVersion()` ### Returns - **String** - the required version ``` -------------------------------- ### Verify PGP signature using GPG Source: https://maven.apache.org/enforcer/guides/download.cgi Import the KEYS file and verify the downloaded file's signature using GPG. Ensure you obtain KEYS and the .asc file from the main distribution site, not a mirror. ```shell % gpg --import KEYS % gpg --verify downloaded_file.asc downloaded_file ``` -------------------------------- ### execute() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rules/RequirePluginVersions.html This is the entry point for the rule, executing the enforcement logic. ```APIDOC ## execute() ### Description Executes the enforcer rule to validate that all plugins have declared versions. ### Method void ### Parameters None ### Returns None ``` -------------------------------- ### getLog() - EnforcerRuleHelper Source: https://maven.apache.org/enforcer/enforcer-api/apidocs/index-all.html Deprecated. Gets the log. ```APIDOC ## getLog() - Method in interface org.apache.maven.enforcer.rule.api.EnforcerRuleHelper ### Description Deprecated. Gets the log. ### Method getLog ### Returns - The log instance. ``` -------------------------------- ### Verify PGP signatures using pgpk Source: https://maven.apache.org/enforcer/guides/download.html Use pgpk to add the KEYS file and verify the signature of the downloaded file. ```bash % pgpk -a KEYS % pgpv downloaded_file.asc ``` -------------------------------- ### Execute enforcement rules with command-line and configuration handling Source: https://maven.apache.org/enforcer/apidocs/src-html/org/apache/maven/plugins/enforcer/EnforceMojo.html Main execute method that skips when skip flag is set, assembles rules from command line or XML configuration, filters skipped rules, processes config providers, and runs them. Throws MojoExecutionException if no rules are configured and failIfNoRules is set. ```Java public void execute() throws MojoExecutionException { Log log = this.getLog(); if (skip) { log.info("Skipping Rule Enforcement."); return; } Optional rulesFromCommandLine = createRulesFromCommandLineOptions(); List rulesList; // current behavior - rules from command line override all other configured rules. List allRules = enforcerRuleManager.createRules(rulesFromCommandLine.orElse(rules), log); rulesList = filterOutSkippedRules(allRules); List additionalRules = processRuleConfigProviders(rulesList); rulesList = filterOutRuleConfigProviders(rulesList); rulesList.addAll(additionalRules); if (rulesList.isEmpty()) { if (failIfNoRules) { throw new MojoExecutionException( "No rules are configured. Use the skip flag if you want to disable execution."); } else { log.warn("No rules are configured."); return; } } // create my helper PluginParameterExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper(session, evaluator, log, container); // if we are only warning, then disable // failFast if (!fail) { failFast = false; } List errorMessages = new ArrayList<>(); // go through each rule for (int ruleIndex = 0; ruleIndex < rulesList.size(); ruleIndex++) { } } ``` -------------------------------- ### Sample external rules file Source: https://maven.apache.org/enforcer/enforcer-rules/externalRules.html A sample rules file for the externalRules parameter. The rules element expects the same content as in the Enforcer Mojo rules configuration. ```xml org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec jakarta.xml.bind:jakarta.xml.bind-api:*:*:test ``` -------------------------------- ### getExcludes() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rules/dependency/RequireReleaseDeps.html Gets the list of excluded dependencies. ```APIDOC ## getExcludes() ### Description Gets the list of excluded dependencies. ### Method List getExcludes() ### Parameters None ### Returns List - the list of excluded dependencies ``` -------------------------------- ### getVersion() Source: https://maven.apache.org/enforcer/enforcer-rules/apidocs/org/apache/maven/enforcer/rules/version/RequireJavaVersion.html Gets the required version range that was set. ```APIDOC ## getVersion() ### Description Gets the required version. ### Method `public final String getVersion()` ### Returns - **String** - The required version. ``` -------------------------------- ### getComponent(String) - EnforcerRuleHelper Source: https://maven.apache.org/enforcer/enforcer-api/apidocs/index-all.html Deprecated. Gets the component. ```APIDOC ## getComponent(String) - Method in interface org.apache.maven.enforcer.rule.api.EnforcerRuleHelper ### Description Deprecated. Gets the component. ### Method getComponent ### Parameters - **role** (String) - Required - The component role. ### Returns - The component instance. ``` -------------------------------- ### getComponent(Class) - EnforcerRuleHelper Source: https://maven.apache.org/enforcer/enforcer-api/apidocs/index-all.html Deprecated. Gets the component. ```APIDOC ## getComponent(Class) - Method in interface org.apache.maven.enforcer.rule.api.EnforcerRuleHelper ### Description Deprecated. Gets the component. ### Method getComponent ### Parameters - **clazz** (Class) - Required - The component class. ### Returns - The component instance. ``` -------------------------------- ### createRulesFromCommandLineOptions method Source: https://maven.apache.org/enforcer/apidocs/src-html/org/apache/maven/plugins/enforcer/EnforceMojo.html Creates a PlexusConfiguration object based on rules provided via the command line, incorporating existing project configuration if available. ```java private Optional createRulesFromCommandLineOptions() { if (rulesToExecute == null || rulesToExecute.isEmpty()) { return Optional.empty(); } PlexusConfiguration configuration = new DefaultPlexusConfiguration("rules"); for (String rule : rulesToExecute) { PlexusConfiguration configuredRule = null; // Check if there's configuration in the project for this rule and use it if so if (rules != null) { // rule names haven't been normalized yet, so check both with first character upper and lower String ruleLower = Character.toLowerCase(rule.charAt(0)) + rule.substring(1); String ruleUpper = Character.toUpperCase(rule.charAt(0)) + rule.substring(1); configuredRule = rules.getChild(ruleLower, false); if (configuredRule == null) { configuredRule = rules.getChild(ruleUpper, false); } } if (configuredRule != null) { configuration.addChild(configuredRule); } else { configuration.addChild(new DefaultPlexusConfiguration(rule)); } } return Optional.of(configuration); } ``` -------------------------------- ### Best Practice Configuration: Allow site repository with banDistributionManagement Source: https://maven.apache.org/enforcer/enforcer-rules/banDistributionManagement.html Shows how to configure the banDistributionManagement rule to allow site entries while still banning repository and snapshotRepository entries. This is useful in corporate environments where only the corporate pom should define distributionManagement, but site definitions may be allowed in other poms. ```xml [...] org.apache.maven.plugins maven-enforcer-plugin 3.6.3 no-distribution-management-at-all enforce true [...] ``` -------------------------------- ### getComponentMap(String) - EnforcerRuleHelper Source: https://maven.apache.org/enforcer/enforcer-api/apidocs/index-all.html Deprecated. Gets the component map. ```APIDOC ## getComponentMap(String) - Method in interface org.apache.maven.enforcer.rule.api.EnforcerRuleHelper ### Description Deprecated. Gets the component map. ### Method getComponentMap ### Parameters - **role** (String) - Required - The component role. ### Returns - A map of components. ``` -------------------------------- ### getComponentList(String) - EnforcerRuleHelper Source: https://maven.apache.org/enforcer/enforcer-api/apidocs/index-all.html Deprecated. Gets the component list. ```APIDOC ## getComponentList(String) - Method in interface org.apache.maven.enforcer.rule.api.EnforcerRuleHelper ### Description Deprecated. Gets the component list. ### Method getComponentList ### Parameters - **role** (String) - Required - The component role. ### Returns - A list of components. ``` -------------------------------- ### Maven Enforcer Plugin configuration for requireFileChecksum Source: https://maven.apache.org/enforcer/enforcer-rules/requireFileChecksum.html Sample plugin configuration showing how to configure the maven-enforcer-plugin with multiple requireFileChecksum rules, each specifying a file, expected checksum, and hash type. The example includes rules for md5, sha1, sha256, sha384, and sha512 checksums, with fail set to true. ```xml [...] org.apache.maven.plugins maven-enforcer-plugin 3.6.3 enforce-checksum enforce ${project.build.outputDirectory}/foo.txt d41d8cd98f00b204e9800998ecf8427e md5 ${project.build.outputDirectory}/bar.txt da39a3ee5e6b4b0d3255bfef95601890afd80709 sha1 ${project.build.outputDirectory}/baz.txt e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 sha256 ${project.build.outputDirectory}/qux.txt 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b sha384 ${project.build.outputDirectory}/quux.txt cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e sha512 true [...] ``` -------------------------------- ### getComponent(String, String) - EnforcerRuleHelper Source: https://maven.apache.org/enforcer/enforcer-api/apidocs/index-all.html Deprecated. Gets the component. ```APIDOC ## getComponent(String, String) - Method in interface org.apache.maven.enforcer.rule.api.EnforcerRuleHelper ### Description Deprecated. Gets the component. ### Method getComponent ### Parameters - **role** (String) - Required - The component role. - **roleHint** (String) - Required - The role hint. ### Returns - The component instance. ``` -------------------------------- ### getComponent(Class, String) - EnforcerRuleHelper Source: https://maven.apache.org/enforcer/enforcer-api/apidocs/index-all.html Deprecated. Gets the component. ```APIDOC ## getComponent(Class, String) - Method in interface org.apache.maven.enforcer.rule.api.EnforcerRuleHelper ### Description Deprecated. Gets the component. ### Method getComponent ### Parameters - **clazz** (Class) - Required - The component class. - **roleHint** (String) - Required - The role hint. ### Returns - The component instance. ``` -------------------------------- ### Sample Maven POM for a custom Enforcer rule project Source: https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html Use this POM as the starting point for a new jar project that contains a custom Enforcer rule. It declares the required dependencies (enforcer-api, maven-core, javax.inject) with provided scope and configures the sisu-maven-plugin to generate the component index. Note that the target bytecode version must be 1.8 or 11 for Maven versions prior to 3.9.6, and 17 is supported by Maven 3.9.6+. ```xml 4.0.0 custom-rule custom-rule-sample 1.0 My Custom Rule This is my custom rule. 3.6.3 3.9.15 8 8 8 org.apache.maven.enforcer enforcer-api ${api.version} provided org.apache.maven maven-core ${mavenVersion} provided javax.inject javax.inject 1 provided org.eclipse.sisu sisu-maven-plugin 1.0.0 main-index ``` -------------------------------- ### getContainer() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/plugins/enforcer/internal/DefaultEnforcementRuleHelper.html Gets the container. This method is specified by the EnforcerRuleHelper interface. ```APIDOC ## Method: getContainer ### Description Gets the container. ### Method Signature public org.codehaus.plexus.PlexusContainer getContainer() ### Returns - **org.codehaus.plexus.PlexusContainer** - The container. ``` -------------------------------- ### Method: execute() Source: https://maven.apache.org/enforcer/enforcer-rules/apidocs/org/apache/maven/enforcer/rules/dependency/BanTransitiveDependencies.html Executes the rule, checking for transitive dependencies and failing the build if any are found (unless excluded). ```APIDOC ## Method: execute ### Description Executes the rule, banning transitive dependencies. ### Signature `public void execute() throws EnforcerRuleException` ### Throws - **EnforcerRuleException** - if the rule fails. ``` -------------------------------- ### HelpMojo() Source: https://maven.apache.org/enforcer/maven-enforcer-plugin/apidocs/org/apache/maven/plugins/maven_enforcer_plugin/HelpMojo.html Constructor for the HelpMojo class. It is a public no-argument constructor used to instantiate the Mojo. ```APIDOC ## HelpMojo() ### Description Public constructor for the HelpMojo class. It is used to create an instance of the Mojo. ### Method Constructor ### Signature `public HelpMojo()` ### Parameters None ### Returns No return value (constructor). ``` -------------------------------- ### getLog() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/plugins/enforcer/internal/DefaultEnforcementRuleHelper.html Gets the log. This method is specified by the EnforcerRuleHelper interface. ```APIDOC ## Method: getLog ### Description Gets the log. ### Method Signature public org.apache.maven.plugin.logging.Log getLog() ### Returns - **log** (org.apache.maven.plugin.logging.Log) - The log. ``` -------------------------------- ### getRegexMessage() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rules/property/RequireProperty.html Gets a warning message if the regular expression is not matched. ```APIDOC ## getRegexMessage() ### Description Gets a warning message if the regular expression is not matched. ### Method `public final String getRegexMessage()` ### Returns - **String** - The regex message. ``` -------------------------------- ### isReactorVersionConsistent Method and XML Configuration Example Source: https://maven.apache.org/enforcer/enforcer-rules/apidocs/src-html/org/apache/maven/enforcer/rules/ReactorModuleConvergence.html Checks for version consistency across multi-module builds. The XML snippet illustrates the parent-child version mismatch scenario this method detects. ```xml ... ... 1.0-SNAPSHOT 1.1-SNAPSHOT ``` ```java private List isReactorVersionConsistent(List projectList) { List result = new ArrayList<>(); if (projectList != null && !projectList.isEmpty()) { String version = projectList.get(0).getVersion(); getLog().debug("First version:" + version); for (MavenProject mavenProject : projectList) { getLog().debug(" -> checking " + mavenProject.getId()); if (!version.equals(mavenProject.getVersion())) { result.add(mavenProject); } } } return result; } ``` -------------------------------- ### getSource() - Deprecated Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rule/api/EnforcerRuleException.html Deprecated method that gets the source. Not used. ```APIDOC ## getSource() - Deprecated ### Description Deprecated. Gets the source. Not used. ### Method `@Deprecated public Object getSource()` ### Returns - **Object** - The source. ``` -------------------------------- ### Scan Project Repositories and Ban Check Source: https://maven.apache.org/enforcer/enforcer-rules/apidocs/src-html/org/apache/maven/enforcer/rules/RequireNoRepositories.html Implements the main rule execution: builds allowed repository lists from settings, then scans each project model's repositories and plugin repositories to find banned ones, optionally appending a custom message before throwing EnforcerRuleException. ```java 133 Collection reposIdsFromSettings = getRepoIdsFromSettings(Profile::getRepositories); 134 if (!reposIdsFromSettings.isEmpty()) { 135 getLog().debug(() -> "Allow repositories from settings: " + reposIdsFromSettings); 136 } 137 138 allowedRepositories = Optional.ofNullable(allowedRepositories).orElseGet(ArrayList::new); 139 allowedRepositories.addAll(reposIdsFromSettings); 140 } 141 142 if (banPluginRepositories) { 143 Collection reposIdsFromSettings = getRepoIdsFromSettings(Profile::getPluginRepositories); 144 if (!reposIdsFromSettings.isEmpty()) { 145 getLog().debug(() -> "Allow plugin repositories from settings: " + reposIdsFromSettings); 146 } 147 148 allowedPluginRepositories = 149 Optional.ofNullable(allowedPluginRepositories).orElseGet(ArrayList::new); 150 allowedPluginRepositories.addAll(reposIdsFromSettings); 151 } 152 153 List sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); 154 155 List models = new ArrayList<>(); 156 for (MavenProject mavenProject : sortedProjects) { 157 getLog().debug("Scanning project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() 158 + VERSION + mavenProject.getVersion()); 159 models.add(mavenProject.getOriginalModel()); 160 } 161 162 List badModels = new ArrayList<>(); 163 164 StringBuilder newMsg = new StringBuilder(); 165 newMsg.append("Some poms have repositories defined:" + System.lineSeparator()); 166 167 for (Model model : models) { 168 if (banRepositories) { 169 List repos = model.getRepositories(); 170 if (repos != null && !repos.isEmpty()) { 171 List bannedRepos = 172 findBannedRepositories(repos, allowedRepositories, allowSnapshotRepositories); 173 if (!bannedRepos.isEmpty()) { 174 badModels.add(model); 175 newMsg.append(model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() 176 + " has repositories " + bannedRepos); 177 } 178 } 179 } 180 if (banPluginRepositories) { 181 List repos = model.getPluginRepositories(); 182 if (repos != null && !repos.isEmpty()) { 183 List bannedRepos = 184 findBannedRepositories(repos, allowedPluginRepositories, allowSnapshotPluginRepositories); 185 if (!bannedRepos.isEmpty()) { 186 badModels.add(model); 187 newMsg.append(model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() 188 + " has plugin repositories " + bannedRepos); 189 } 190 } 191 } 192 } 193 194 // if anything was found, log it then append the 195 // optional message. 196 if (!badModels.isEmpty()) { 197 if (StringUtils.isNotEmpty(getMessage())) { 198 newMsg.append(getMessage()); 199 } 200 201 throw new EnforcerRuleException(newMsg.toString()); 202 } 203 } ``` -------------------------------- ### getContainer() Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/plugins/enforcer/internal/DefaultEnforcementRuleHelper.html Gets the Plexus container. This method is part of the EnforcerRuleHelper interface. ```APIDOC ## getContainer() ### Description Gets the Plexus container. ### Method public org.codehaus.plexus.PlexusContainer getContainer() ### Returns - **PlexusContainer** - The Plexus container. ``` -------------------------------- ### getLongMessage() - Deprecated Source: https://maven.apache.org/enforcer/apidocs/org/apache/maven/enforcer/rule/api/EnforcerRuleException.html Deprecated method that gets the long message. Not used. ```APIDOC ## getLongMessage() - Deprecated ### Description Deprecated. Gets the long message. Not used. ### Method `@Deprecated public String getLongMessage()` ### Returns - **String** - The long message. ``` -------------------------------- ### Calculate hash using certUtil on Windows Source: https://maven.apache.org/enforcer/guides/download.cgi Use certUtil on Windows 7 and later to compute a file hash. HashAlgorithm choices include MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512. ```shell % certUtil -hashfile pathToFileToCheck ``` -------------------------------- ### Configure reactorModuleConvergence in pom.xml Source: https://maven.apache.org/enforcer/enforcer-rules/reactorModuleConvergence.html Example configuration for the maven-enforcer-plugin using the reactorModuleConvergence rule. ```xml 1. 2. [...] 3. 4. 5. 6. org.apache.maven.plugins 7. maven-enforcer-plugin 8. 3.6.3 9. 10. 11. enforce-no-snapshots 12. 13. enforce 14. 15. 16. 17. 18. The reactor is not valid 19. true 20. 21. 22. true 23. 24. 25. 26. 27. 28. 29. [...] 30. ``` -------------------------------- ### Get EnforcerLevel from Configuration Source: https://maven.apache.org/enforcer/apidocs/src-html/org/apache/maven/plugins/enforcer/internal/EnforcerRuleManager.html Extracts the EnforcerLevel from the provided PlexusConfiguration, defaulting to ERROR if not specified. ```java private EnforcerLevel getRuleLevelFromConfig(PlexusConfiguration ruleConfig) { PlexusConfiguration levelConfig = ruleConfig.getChild("level", false); String level = Optional.ofNullable(levelConfig) .map(PlexusConfiguration::getValue) .orElse(EnforcerLevel.ERROR.name()); return EnforcerLevel.valueOf(level); } ```