Mavenでは、プラグインがアクティブ化されていないアクティブ化プロファイル内で宣言されている場合、拡張パッケージングタイプは「不明なパッケージングエラー」をスローします

マラソン

たとえば、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以外のすべてのOSで何もしないことを望んでいます。

これを修正するにはどうすればよいですか?

ポールヒックス

あなたの懸念を分離します。

  1. パッケージを定義します。これはプロファイルで発生する必要はありません。含まれている場合は、activeByDefaultプロファイルである必要があります。
  2. 要件に基づいてプロジェクトを制限します。
    • ビルドに失敗したい場合は、エンフォーサープラグインがこれを行います。
    • narのビルドをスキップしたい場合は、デフォルトのプロファイルを使用して、skipNar構成アイテムでnarプラグインを構成できます。Macプロファイルで、skipNar構成アイテムなしで新しい構成を作成します。

このスニペット(enforceプラグインのWebサイトから取得し、少し変更したもの)は、fail-the-buildオプションで機能するはずです。

  <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>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ