问题
I have one Parent maven project and 4 modules in that project:
Now I want to put some custom rule that says there can be no project versions or dependency versions that begin with the string "master-". This rule will be applicable to all the external projects that depends on eBill Software.
So I created a new module with name customRule whose parent is again eBill Software. I followed writing-a-custom-rule and my rule class is in new module.
Relevant part of CustomRule.java in module customRule:
MavenProject project = (MavenProject) helper.evaluate( "${project}" );
Set<Artifact> artifacts = project.getArtifacts();
boolean containsInvalid = artifacts.stream()
.filter(item -> item.getVersion()
.startsWith("master-"))
.anyMatch(item -> true);
if(containsInvalid) {
this.shouldIfail = true;
}
Relevant part of customRule module pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-no-master-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<myCustomRule implementation="org.apache.customRule.CustomRule">
<shouldIfail>false</shouldIfail>
</myCustomRule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Now I want to access this custom rule in parent module eBill Software:
So what should I enter in its pom.xml and external project's pom.xml to be able to get the custom rule applicable to all the external projects that depends on eBill Software.
来源:https://stackoverflow.com/questions/48315914/enforce-custom-rule-in-external-projects