2017-05-16 11 views
2

mavenで条件付きでプロパティを設定したいのですが、それはスナップショットビルドであるかどうかによって異なります。擬似コードは次のようになります。mavenで条件付きでプロパティを設定する

if ${project.version} ends with "-SNAPSHOT"  
then 
    deployFileUrl = ${project.distributionManagement.snapshotRepository.url} 
else 
    deployFileUrl = ${project.distributionManagement.repository.url} 

これはどのように実装できますか?

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
     <executions> 
      <execution> 
       <id>regex-properties</id> 
       <goals> 
        <goal>regex-properties</goal> 
       </goals> 
        <configuration> 
         <regexPropertySettings> 
          <regexPropertySetting> 
           <name>deployFileUrl</name> 
           <value>${project.version}</value> 
           <regex>.*-SNAPSHOT</regex> 
           <replacement>${project.distributionManagement.snapshotRepository.url}</replacement> 
           <failIfNoMatch>false</failIfNoMatch> 
          </regexPropertySetting> 
         </regexPropertySettings> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

を次のように私はビルドヘルパーのmaven-pluginのでそれを試してみました。このアプローチの問題は、私は他の条件を実装することができないということです。

+1

を次のように最後に、私は(http://maven.apache.org/guides/introduction/introduction-to-profiles.html)[プロファイルのビルド]のmaven-antrun-プラグインを使用して終了あなたの答えです。 – biziclop

+0

@biziclopは悲しいことです。 Mavenはアリのようなものではありません。論理をすることは本当に決して考えられませんでした。 Mavenでスクリプトを作成する場合は、Maven Antプラグインを使用してみてください。 – Richard

+0

@biziclopスナップショットであるかどうかに基づいて対応するプロファイルを有効にする方法が必要です。他の条件が存在する場合は... –

答えて

0

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <executions> 
     <execution> 
      <phase>validate</phase> 
      <configuration> 
       <exportAntProperties>true</exportAntProperties> 
       <target> 
        <condition property="isSnapshot"> 
         <contains string="${project.version}" substring="SNAPSHOT" /> 
        </condition> 
        <condition property="deployFileUrl" 
         value="${project.distributionManagement.snapshotRepository.url}"> 
         <isset property="isSnapshot" /> 
        </condition> 
        <!-- Properties in ant are immutable, so the following assignments 
         will only take place if deployFileUrl is not yet set. --> 
        <property name="deployFileUrl" 
         value="${project.distributionManagement.repository.url}" /> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
2

Mavenによって自動的に処理されるのは、すべてのことが原因です。 1.2.3のようなリリースバージョンである場合、mavenはリリースリポジトリを使用し、バージョンが '1.2.3-SNAPSHOT`のようなSNAPSHOTバージョンであれば、mavenはスナップショットリポジトリを使用します。

+0

私にそれを教える人がいることは分かっていました。残念ながら、私は特定のケースでこれを管理する方法を理解していませんでした。問題は、proguard-maven-pluginを使って難解なプロジェクトのjarをビルドすることです。このプラグインは、追加のjarを生成します。これは、後で対応するプラグインをインストールして展開する必要があります。 maven-deploy-pluginにURL(スナップショットまたはリリースのリポジトリURL)を指定する必要があります。 –

+0

これはあなたの設定が間違っていると聞きます...プラグインはプロジェクトに適切なjarファイルを添付し、展開段階では自動的にリモートリポジトリに転送されます。実際のpomファイルがなければどこに問題があるのか​​分かりません。 .. – khmarbaise

関連する問題