繁体   English   中英

在maven中,如果插件在未激活的激活配置文件中声明,则扩展打包类型会抛出“未知打包错误”

[英]in maven, an extension packaging type throws “unknown packaging error” if the plugin is declared inside an activation profile that is not activated

例如,NAR插件定义了一种名为“nar”的新包装类型。

在一个简单的情况下工作正常:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>blah</groupId>
    <version>1</version>
    <artifactId>blahblab</artifactId>

    <packaging>nar</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.0.0</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

但是,如果您将该构建嵌套到未激活的激活配置文件 ,例如在linux上运行此pom:

<?xml version="1.0" encoding="UTF-8"?>
<project>

    <modelVersion>4.0.0</modelVersion>

    <groupId>blah</groupId>
    <version>1</version>
    <artifactId>blahblab</artifactId>

    <packaging>nar</packaging>

    <profiles>
        <!-- won't get activated on linux -->
        <profile>
            <id>some-exotic-os-only</id>
            <activation>
                <os>
                    <family>Mac OS</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.maven-nar</groupId>
                        <artifactId>nar-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <extensions>true</extensions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

Maven不再知道nar的意思和窒息。

#  mvn -U help:active-profiles
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project blah:blahblab:1 (/tmp/test/pom.xml) has 1 error
[ERROR]     Unknown packaging: nar @ line 13, column 16
[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/ProjectBuildingException

在mac上运行它,没关系。 但是这种情况违背了概况...我希望除了mac之外,我不会对所有操作系统做任何事情。

我该如何解决?

分开你的顾虑。

  1. 定义您的包装。 这不需要在配置文件中发生; 如果是,则必须是activeByDefault配置文件。
  2. 根据您的要求限制您的项目。
    • 如果您想使构建失败,则enforcer插件将为您执行此操作。
    • 如果要跳过构建nar,则可以使用默认配置文件使用skipNar配置项配置nar插件。 在您的mac配置文件中,创建一个没有skipNar配置项的新配置。

这段代码(从强制插件的网站中提取,并进行了一些修改)应该适用于构建失败的选项。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <executions>
      <execution>
        <id>enforce-versions</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <requireOS>
              <family>mac</family>
            </requireOS>
          </rules>
        </configuration>
      </execution>
    </executions>
  </plugin>

对于skipNar选项,对此的一些变化可能适合您。

<profiles>
  <profile>
    <id>noBuildNar</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <plugins>
      <plugin>
         <groupId>com.github.maven-nar</groupId>
         <artifactId>nar-maven-plugin</artifactId>
         <configuration>
           <skipNar/>
         </configuration>
       </plugin>
     </plugins>
  </profile>

  <profile>
    <id>buildNar</id>
    <activation>
      <family>mac</family>
    </activation>
    <plugins>
      <plugin>
         <groupId>com.github.maven-nar</groupId>
         <artifactId>nar-maven-plugin</artifactId>
       </plugin>
     </plugins>
  </profile>
</profiles>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM