开发者

Maven - run plugin once per profile

I have one Maven module responsible with building some docs out of several other modules (wars). All works fine -> at build i combine several plugins like javadoc, wadl, assembly, etc. to perform what I want. Now it seems i need to build the same doc for multiple versions (so we have doc for both trunk and older versions). I tried to use profiles like the config below. The problem is that even both profiles are active, each plugin executes only once (even though they have different executio开发者_JS百科n ids). Any idea why and how I can trigger each plugin to run once per profile?

<dependencies>
  <!-- common dependencies -->
</dependencies>
<properties>
  <!-- ${versionToBuild} is defined by each profile -->
  <output.name>doc-${versionToBuild}</output.name> 
  <!-- other common properties or based on a property defined by profile -->
</properties>
 <build>
    <pluginManagement>
        <plugins>
        <!-- configuration for plugins based on $versionToBuild -->
        </plugins>
    </pluginManagement>
 </build>
 <profiles>
   <profile>
     <id>doc-for-1.1</id>
     <activation>
       <activeByDefault>true</activeByDefault>
     </activation>
     <properties>
       <versionToBuild>1.1-SNAPSHOT</versionToBuild>
     </properties>
     <dependencies>
       <!-- the artefacts of my project in v1.1 -->
     </dependencies>
     <build>
       <plugins>
         <plugin>
           <artifactId>maven-javadoc-plugin</artifactId>
         </plugin>
         <plugin>
           <groupId>com.sun.jersey.contribs</groupId>
           <artifactId>maven-wadl-plugin</artifactId>
         </plugin>
       <plugins>
     </build>
   </profile>
   <profile>
     <id>doc-for-1.2</id>
     <activation>
       <activeByDefault>true</activeByDefault>
     </activation>
     <properties>
       <versionToBuild>1.2-SNAPSHOT</versionToBuild>
     </properties>
     <dependencies>
       <!-- the artefacts of my project in v1.2 -->
     </dependencies>
     <build>
       <plugins>
         <plugin>
           <artifactId>maven-javadoc-plugin</artifactId>
         </plugin>
         <plugin>
           <groupId>com.sun.jersey.contribs</groupId>
           <artifactId>maven-wadl-plugin</artifactId>
         </plugin>
       <plugins>
     </build>
   </profile>
 </profiles> 


I don't think you can do what you want without going against the grain of how Maven works. It does trickery to merge overlapping plugin configurations such as yours. You could bind each plugin to different phase to its default (ensuring they are different for v1.1 and v1.2), but it's very hacky.

Instead, I advise having separate branches on your source control for v1.1 and v1.2, instead of the POM being coupled so tightly to the version history. You would just build the doc for each version by checking out the appropriate branch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜