Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MENFORCER-425] clarify class loading of custom rules #167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions enforcer-api/src/custom-rule-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer-api</artifactId>
<version>${api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
8 changes: 7 additions & 1 deletion enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ Writing a custom rule
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer-api</artifactId>
<version>${api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -72,7 +75,10 @@ Writing a custom rule
</build>
</project>
+---+

Note that the classloader is shared with the embedding <<<maven-enforcer-plugin>>> (a regular {{{https://maven.apache.org/guides/mini/guide-maven-classloading.html#3-plugin-classloaders}plugin classloader}})
and therefore the artifacts <<<org.apache.maven.enforcer:enforcer-api>>> and <<<org.apache.maven.enforcer:enforcer-rules>>> are always loaded in the same version as the embedding <<<maven-enforcer-plugin>>>.
Custom rule artifacts should therefore only depend on them and core Maven artifacts with <<<provided>>> scope (for details refer to {{{https://issues.apache.org/jira/browse/MNG-7097}MNG-7097}}).

[[2]] Create your rule class. The rule must implement the {{{./apidocs/index.html}EnforcerRule}} interface.
The rule can get access to components and the log via the {{{./apidocs/index.html}EnforcerRuleHelper}} interface.
In addition, the rule must provide a setter method for each parameter allowed to be configured in the pom.xml file (like the parameter <<<shouldIfail>>> shown in point 5).
Expand Down