これは私の pom.xml からの抜粋です。以下を試しましたが、プロファイルはアクティブ化されませんでした。
mvn clean install -Pdev1
mvn clean install -P dev1
試してみたところ、mvn help:active-profiles
アクティブなプロファイルはリストされませんでした。を<activeByDefault>
に設定し、 を実行すると、プロファイルがアクティブになっていることが示されます。dev1
true
mvn help:active-profiles
<profile>
<id>dev1</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<env>local</env>
<properties.file>src/test/resources/dev1.properties</properties.file>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/dev1.testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dev2</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<env>local</env>
<properties.file>src/test/resources/dev2.properties</properties.file>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/dev2.testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
なぜ自分のプロフィールがアクティブ化されないのか疑問に思っています。同様の問題に遭遇した人はいますか?
ベストアンサー1
どちらのコマンドも正しいです:
mvn clean install -Pdev1
mvn clean install -P dev1
問題はおそらくプロファイルの有効化ではなく、プロファイル期待通りの結果が出ない。
次のコマンドは正常です:
mvn help:active-profiles
が含まれていないため、プロファイルは表示されません-Pdev1
。 を追加してプロファイルを表示することもできますが、Maven 自体をテストすることになるため意味がありません。
あなたがすべきことはプロフィールの動作を確認する以下の手順を実行します。
- プロファイル設定で設定
activeByDefault
し、true
- 実行します
mvn help:active-profiles
( がなくても常にアクティブになっていることを確認するため-Pdev1
)、 - 走る
mvn install
。
以前と同じ結果が生成されるので、問題はプロファイルが期待どおりに動作していないことであることが確認できます。