2011-08-16 14 views
11

複数のアセンブリ実行を持つpomがあります。私が走ったとき、例えば。 mvn package、すべての実行を実行します。 fooの実行のみを実行するように指示するにはどうすればよいですか?Maven:どのアセンブリプラグイン実行が実行されるかを指定する方法

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>foo/id> 
        <phase>package</phase> 
        <goals><goal>single</goal></goals> 
        <configuration>...</configuration> 
       </execution> 
       <execution> 
        <id>bar</id> 
        <phase>package</phase> 
        <goals><goal>single</goal></goals> 
        <configuration>...</configuration> 
       </execution> 

私は上記の持っていることは、私の心の中で、次のようMakefileのようになります。

all: foo bar 

foo: 
    ... build foo ... 

bar: 
    ... build bar ... 

私はすべてを構築するためにmake allまたは単にmakeを実行することができ、または私がmake fooまたはmake barを実行することができます個々のターゲットを構築する。 Mavenでこれをどうすれば実現できますか?

答えて

25

あなたはprofilesを使用する必要があり、ここにpom.xml例です。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.mycompany</groupId> 
    <artifactId>FooBar</artifactId> 
    <version>1.0</version> 
    <packaging>jar</packaging> 

    <profiles> 

     <profile> 
      <id>Foo</id> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-assembly-plugin</artifactId> 
         <executions> 
         <execution> 
          <id>foo/id> 
          <phase>package</phase> 
          <goals><goal>single</goal></goals> 
          <!-- configuration>...</configuration --> 
         </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 

     <profile> 
      <id>Bar</id> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-assembly-plugin</artifactId> 
         <executions> 
         <execution> 
          <id>Bar</id> 
          <phase>package</phase> 
          <goals><goal>single</goal></goals> 
          <!-- configuration>...</configuration --> 
         </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 

    </profiles> 

</project> 

そして、あなたはこのようにMavenを呼び出します:

mvn package -P Foo // Only Foo 
mvn package -P Bar // Only Bar 
mvn package -P Foo,Bar // All (Foo and Bar) 
8

私のMavenは少し錆びですが、私はあなたがこの方法のカップル行うことができると思います:プロファイルを使用してください)

1。コマンドラインで "maven -PprofileName"を指定してプロファイルを指定します。

2)実行を別々のフェーズ/ゴールに置き、必要なものだけを実行します。

2

"bar"を実行しない場合は、ライフサイクルフェーズにバインドしないでください。プラグインの実行は、フェーズにバインドされているときにのみ実行され、そのフェーズはビルドの一部として実行されます。 TheCoolahが示唆しているように、プロファイルはライフサイクル・フェーズに拘束されているときとそうでないときに管理する1つの方法です。

関連する問題