我很容易被执法者插件中的规则失败匹配所困扰。正则表达式验证版本属性,但是当相同的正则表达式应用于 project.parent.version (在显示的pom中注释掉)时,它会失败:
Image must not have a SNAPSHOT parent 18:
我的maven版本是3.3.9,这是我的完整pom:
<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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>appimage-test</artifactId>
<packaging>pom</packaging>
<groupId>test</groupId>
<version>2.0.0</version>
<properties>
<revision>18</revision>
</properties>
<parent>
<groupId>mygrp</groupId>
<artifactId>artifact_id</artifactId>
<version>18</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-image-revision-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<!--
<requireProperty>
<property>project.parent.version</property>
<regex>\d\d</regex>
<regexMessage>Image must not have a SNAPSHOT parent ${project.parent.version}:</regexMessage>
</requireProperty>
-->
<requireProperty>
<property>revision</property>
<regex>\d\d</regex>
<regexMessage>Regex did not match:${revision}:</regexMessage>
</requireProperty>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
将 project.parent.version 的表达式更改为\ d +。*会使它通过\ d \ d。*和\ d +不...(如果你想知道为什么我不要使用什么有效,我需要验证一个更复杂的正则表达式,所以我试图理解我在这里缺少的东西)
此处的评论请求是调试日志输出:
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-enforcer-plugin:1.4.1, parent: sun.misc.Launcher$AppClassLoader@46c9220]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce' with basic configurator -->
[DEBUG] (s) fail = true
[DEBUG] (s) failFast = false
[DEBUG] (f) ignoreCache = false
[DEBUG] (f) mojoExecution = org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce {execution: enforce-image-revision-property}
[DEBUG] (s) project = MavenProject: test:appimage-test:2.0.0 @ /home/myuser/myproject/pom.xml
[DEBUG] (s) property = project.parent.version
[DEBUG] (s) regex = \d+
[DEBUG] (s) regexMessage = Image must not have a SNAPSHOT parent 18:
[DEBUG] (s) property = revision
[DEBUG] (s) regex = \d\d
[DEBUG] (s) regexMessage = Regex did not match:18:
[DEBUG] (s) rules = [org.apache.maven.plugins.enforcer.RequireProperty@4c500a2, org.apache.maven.plugins.enforcer.RequireProperty@21ac8e20]
[DEBUG] (s) session = org.apache.maven.execution.MavenSession@47a6e825
[DEBUG] (s) skip = false
[DEBUG] -- end configuration --
[DEBUG] Executing rule: org.apache.maven.plugins.enforcer.RequireProperty
[DEBUG] Adding failure due to exception
org.apache.maven.enforcer.rule.api.EnforcerRuleException: Image must not have a SNAPSHOT parent 18:
at org.apache.maven.plugins.enforcer.AbstractPropertyEnforcerRule.execute(AbstractPropertyEnforcerRule.java:127)
at org.apache.maven.plugins.enforcer.EnforceMojo.execute(EnforceMojo.java:193)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[DEBUG] Executing rule: org.apache.maven.plugins.enforcer.RequireProperty
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
Image must not have a SNAPSHOT parent 18:
我对发布完整的调试日志犹豫不决,因为我很难正确地清理它,但这里是插件版本控制信息:
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=1, ConflictMarker.markTime=0, ConflictMarker.nodeCount=137, ConflictIdSorter.graphTime=1, ConflictIdSorter.topsortTime=0, ConflictIdSorter.conflictIdCount=49, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=8, ConflictResolver.conflictItemCount=112, DefaultDependencyCollector.collectTime=150, DefaultDependencyCollector.transformTime=10}
[DEBUG] org.apache.maven.plugins:maven-enforcer-plugin:jar:1.4.1:
[DEBUG] org.apache.maven:maven-artifact:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-plugin-api:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-project:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-settings:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-profile:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-model:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-artifact-manager:jar:2.2.1:compile
[DEBUG] backport-util-concurrent:backport-util-concurrent:jar:3.1:compile
[DEBUG] org.apache.maven:maven-plugin-registry:jar:2.2.1:compile
[DEBUG] org.codehaus.plexus:plexus-interpolation:jar:1.11:compile
[DEBUG] org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
[DEBUG] org.apache.maven:maven-core:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-plugin-parameter-documenter:jar:2.2.1:compile
[DEBUG] org.slf4j:slf4j-jdk14:jar:1.5.6:runtime
[DEBUG] org.slf4j:slf4j-api:jar:1.5.6:runtime
[DEBUG] org.slf4j:jcl-over-slf4j:jar:1.5.6:runtime
[DEBUG] org.apache.maven.reporting:maven-reporting-api:jar:2.2.1:compile
[DEBUG] org.apache.maven.doxia:doxia-sink-api:jar:1.1:compile
[DEBUG] org.apache.maven.doxia:doxia-logging-api:jar:1.1:compile
[DEBUG] org.apache.maven:maven-repository-metadata:jar:2.2.1:compile
[DEBUG] org.apache.maven:maven-error-diagnostics:jar:2.2.1:compile
[DEBUG] commons-cli:commons-cli:jar:1.2:compile
[DEBUG] org.apache.maven:maven-plugin-descriptor:jar:2.2.1:compile
[DEBUG] org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile
[DEBUG] org.apache.maven:maven-monitor:jar:2.2.1:compile
[DEBUG] classworlds:classworlds:jar:1.1:compile
[DEBUG] org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[DEBUG] org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[DEBUG] org.codehaus.plexus:plexus-utils:jar:3.0.22:compile
[DEBUG] commons-lang:commons-lang:jar:2.3:compile
[DEBUG] org.apache.maven.enforcer:enforcer-api:jar:1.4.1:compile
[DEBUG] org.apache.maven.enforcer:enforcer-rules:jar:1.4.1:compile
[DEBUG] org.apache.maven.shared:maven-common-artifact-filters:jar:1.4:compile
[DEBUG] org.beanshell:bsh:jar:2.0b4:compile
[DEBUG] org.apache.maven.shared:maven-dependency-tree:jar:2.2:compile
[DEBUG] org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[DEBUG] org.eclipse.aether:aether-util:jar:0.9.0.M2:compile
[DEBUG] org.codehaus.plexus:plexus-i18n:jar:1.0-beta-6:compile
[DEBUG] org.apache.maven.plugin-testing:maven-plugin-testing-harness:jar:1.3:compile
[DEBUG] org.codehaus.plexus:plexus-archiver:jar:2.2:compile
[DEBUG] org.codehaus.plexus:plexus-io:jar:2.0.4:compile
[DEBUG] junit:junit:jar:4.11:compile
[DEBUG] org.hamcrest:hamcrest-core:jar:1.3:compile
[DEBUG] Created new class realm plugin>org.apache.maven.plugins:maven-enforcer-plugin:1.4.1
[DEBUG] Importing foreign packages into class realm plugin>org.apache.maven.plugins:maven-enforcer-plugin:1.4.1
[DEBUG] Imported: < project>test:appimage-test:2.0.0
[DEBUG] Populating class realm plugin>org.apache.maven.plugins:maven-enforcer-plugin:1.4.1
[DEBUG] Included: org.apache.maven.plugins:maven-enforcer-plugin:jar:1.4.1
[DEBUG] Included: backport-util-concurrent:backport-util-concurrent:jar:3.1
[DEBUG] Included: org.codehaus.plexus:plexus-interpolation:jar:1.11
[DEBUG] Included: org.slf4j:slf4j-jdk14:jar:1.5.6
[DEBUG] Included: org.slf4j:jcl-over-slf4j:jar:1.5.6
[DEBUG] Included: org.apache.maven.reporting:maven-reporting-api:jar:2.2.1
[DEBUG] Included: org.apache.maven.doxia:doxia-sink-api:jar:1.1
[DEBUG] Included: org.apache.maven.doxia:doxia-logging-api:jar:1.1
[DEBUG] Included: commons-cli:commons-cli:jar:1.2
[DEBUG] Included: org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4
[DEBUG] Included: org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3
[DEBUG] Included: org.sonatype.plexus:plexus-cipher:jar:1.4
[DEBUG] Included: org.codehaus.plexus:plexus-utils:jar:3.0.22
[DEBUG] Included: commons-lang:commons-lang:jar:2.3
[DEBUG] Included: org.apache.maven.enforcer:enforcer-api:jar:1.4.1
[DEBUG] Included: org.apache.maven.enforcer:enforcer-rules:jar:1.4.1
[DEBUG] Included: org.apache.maven.shared:maven-common-artifact-filters:jar:1.4
[DEBUG] Included: org.beanshell:bsh:jar:2.0b4
[DEBUG] Included: org.apache.maven.shared:maven-dependency-tree:jar:2.2
[DEBUG] Included: org.codehaus.plexus:plexus-component-annotations:jar:1.5.5
[DEBUG] Included: org.eclipse.aether:aether-util:jar:0.9.0.M2
[DEBUG] Included: org.codehaus.plexus:plexus-i18n:jar:1.0-beta-6
[DEBUG] Included: org.apache.maven.plugin-testing:maven-plugin-testing-harness:jar:1.3
[DEBUG] Included: org.codehaus.plexus:plexus-archiver:jar:2.2
[DEBUG] Included: org.codehaus.plexus:plexus-io:jar:2.0.4
[DEBUG] Included: junit:junit:jar:4.11
[DEBUG] Included: org.hamcrest:hamcrest-core:jar:1.3
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-enforcer-plugin:1.4.1, parent: sun.misc.Launcher$AppClassLoader@46c9220]