2012-03-13 4 views
1

への結合私はMaven2をカスタムフェーズ

mvn blah:touch 

実行の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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>pram.plugintest</groupId> 
    <artifactId>pram.plugintest</artifactId> 
    <packaging>maven-plugin</packaging> 
    <version>1.1-SNAPSHOT</version> 
    <name>pram.plugintest Maven Mojo</name> 
    <url>http://maven.apache.org</url> 
    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-plugin-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <goalPrefix>blah</goalPrefix> 
       </configuration> 
      </plugin> 
     </plugins> 
     <resources> 
      <resource> 
       <directory>src/main/resources</directory> 
      </resource> 
     </resources> 
    </build> 
    <dependencies> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-plugin-api</artifactId> 
     <version>2.0</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
</project> 

を使用して定義された予想通り、ターゲットディレクトリ内のテキストファイルを作成しているカスタムプラグインを持っています。私は今、別のMavenプロジェクトでポンポン

<lifecycles> 
    <lifecycle> 
     <id>touch</id> 
     <phases> 
      <phase> 
       <id>package</id> 
       <executions> 
        <execution> 
         <goals> 
          <goal>touch</goal> 
         </goals> 
        </execution> 
       </executions> 
      </phase> 
     </phases> 
    </lifecycle> 
</lifecycles> 

に指定されたリソースディレクトリにあるlifecycles.xmlファイルを作成し、私はこの

... 
<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
     <id>test1</id> 
     <phase>blah:touch</phase> 
     <goals> 
      <goal>java</goal> 
     </goals> 
     <configuration> 
<mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass> 
     </configuration> 
    </execution> 
</executions> 
</plugin> 
... 
に似て実行タスクに mvn blah:touchの実行をバインドしたいと思います

これを実行すると、テキストファイルが作成されますが、実行しようとしません。org.sonatype.mavenbook.weather.Main

これは正しい方法ですか?

究極的には、exec-maven-pluginにデフォルトのフェーズにバインドされていない複数の実行セクションを用意することです。論理的にはそれは私がmvn blah:touchを実行した場合、その後org.sonatype.mavenbook.weather.Mainが実行されると、私はmvn blah:touch2を実行した場合、その後org.sonatype.mavenbook.weather.SomeOtherClassが代わりに実行されますので、この

... 
<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
     <id>test1</id> 
     <phase>blah:touch</phase> 
     <goals> 
      <goal>java</goal> 
     </goals> 
     <configuration> 
<mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass> 
     </configuration> 
    </execution> 
<execution> 
     <id>test2</id> 
     <phase>blah:touch2</phase> 
     <goals> 
      <goal>java</goal> 
     </goals> 
     <configuration> 
<mainClass>mainClass=org.sonatype.mavenbook.weather.SomeOtherClass</mainClass> 
     </configuration> 
    </execution> 
</executions> 
</plugin> 
... 

ようになります。

これは簡単なことですが、これを行う方法を指摘しているようなものはありません。documentation

答えて

1

あなたはこのためにのexec-のmaven-pluginのを使用することはできませんし、あなただけのビルド中にあなたのプラグインを実行したい場合は、lifecycle.xmlを必要としません。特定のMavenの段階で、あなたのプラグインを実行するには

、あなたは単に

<plugins> 
     <plugin> 
      <groupId>your.group.id</groupId> 
      <artifactId>your.artifact.id</artifactId> 
      <executions> 
       <execution> 
        <id>unique-execution-id</id> 
        <goals> 
         <goal>the.goal.of.your.plugin</goal> 
        </goals> 
        <phase>maven.phase</phase> 
        <configuration> 
        .... 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 

を追加する必要が接頭辞なし目標要素でゴールを指定してください。

http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.htmlを読んだことがありますか?

+0

私が達成したいのは、exec-maven-pluginの異なる実行セクションがデフォルト以外のフェーズにリンクされていることです。元の投稿でこれを展開します – Pram

関連する問題