2012-08-24 26 views
5

我有maven-jaxb2插件。我生成jaxb對象並將其引用到其他類的項目中。我已將jaxb插件和編譯器插件放在pluginManagement標記下。 Maven首先執行的是編譯階段,而不是生成階段,就好像我刪除了pluginManagement標記,它工作正常,首先生成階段被執行,所有jaxb對象被生成,然後編譯階段被執行。由於pluginManagement標籤,我的項目不能編譯。 pluginManagement標記僅用於定義父pom中的所有插件,以便子pom可以引用這些插件嗎?我的項目不是多模塊項目。如果插件在插件管理下定義,maven目標無法正確執行

<pluginManagement>  
     <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
       <encoding>UTF-8</encoding> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <schemaDirectory>${basedir}/src/main/resources/schema</schemaDirectory> 
       <generatePackage>com.common.dto</generatePackage> 
       <schemaIncludes> 
        <include>*.xsd</include> 
       </schemaIncludes> 
       <removeOldOutput>false</removeOldOutput> 
       <strict>false</strict> 
       <verbose>true</verbose> 
       <forceRegenerate>true</forceRegenerate> 
       <extension>true</extension> 
      </configuration> 
     </plugin> 
    </plugins> 
</pluginManagement> 

回答

5

是,<pluginManagement>用於創建準備使用的配置,但不會自動激活你的插件 - 你仍然需要包括它們。 因此實際上你是對的,<pluginManagement>,就像<dependencyManagement>在父pom中集中插件配置和依賴管理非常有用。

實際上,「聲明」從一個更簡潔的語法,你的插件在正確的模塊的好處:

<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
    </plugin> 

    <plugin> 
     <groupId>org.jvnet.jaxb2.maven2</groupId> 
     <artifactId>maven-jaxb2-plugin</artifactId> 
    </plugin> 
</plugins> 
相關問題