解决Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce

在编译spark-atlas-connector的源码时,遇到下面的报错:

[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-versions) @ spark-atlas-connector-main_2.11 ---
[WARNING] Rule 2: org.apache.maven.plugins.enforcer.RequireOS failed with message:
OS Arch: x86 Family: dos Name: windows 10 Version: 10.0 is not allowed by Family=unix
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] spark-atlas-connector-main_2.11 .................... FAILURE [  2.116 s]
[INFO] spark-atlas-connector_2.11 ......................... SKIPPED
[INFO] spark-atlas-connector-assembly ..................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.189 s
[INFO] Finished at: 2022-08-17T17:06:06+08:00
[INFO] Final Memory: 26M/495M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (enforce-versions) on project spark-atlas-connector-main_2.11: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

刚开始很头疼,搜索了不少“Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce”,还是没解决问题。后面发现上面的“

org.apache.maven.plugins.enforcer.RequireOS failed with message:
OS Arch: x86 Family: dos Name: windows 10 Version: 10.0 is not allowed by Family=unix”

原来, Maven Enforcer 插件提供了非常多的通用检查规则,比如检查 JDK 版本、检查 Maven 版本、 检查依赖版本,等等

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <inherited>false</inherited>
        <configuration>
          <rules>
            <requireMavenVersion>
              <version>[3.0.0,)</version>
            </requireMavenVersion>
            <requireJavaVersion>
              <version>[${minJavaVersion}.0,${maxJavaVersion}.1000}]</version>
            </requireJavaVersion>
            <requireOS>
              <family>unix</family>
            </requireOS>
          </rules>
        </configuration>
        <executions>
          <execution>
            <id>clean</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <phase>pre-clean</phase>
          </execution>
          <execution>
            <id>default</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <phase>validate</phase>
          </execution>
          <execution>
            <id>site</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <phase>pre-site</phase>
          </execution>
        </executions>
      </plugin>

由于是在windows编译,而原来是如下配置的:

<requireOS>
<family>unix</family>
</requireOS>

需要修改如下:

<requireOS>
     <family>windows</family>
 </requireOS>

果然可以顺利编译了。

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注