Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven goal doesn't execute properly if plugins are defined under pluginManagement

I have maven-jaxb2-plugin. I generate jaxb objects and refer it in other classes of project.I've put jaxb plugin and compiler plugin under pluginManagement tag. Maven is executing compile phase first than generate phase where as if i remove pluginManagement tag, it works fine, first generate phase gets executed and all jaxb object gets generated and then compile phase gets executed. Due to pluginManagement tag, my project doesn't compile. Is pluginManagement tag used only for defining all the plugins in parent pom so that child pom can refer to these plugins ? My project is not a multi-module project.

   <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>
like image 840
Pankaj Avatar asked Aug 24 '12 19:08

Pankaj


People also ask

How to configure maven plugin in pom xml?

Next, open the command console and go to the folder containing pom. xml and execute the following mvn command. Maven will start processing and displaying the clean phase of clean life cycle. Plugins are specified in pom.

How do I run a Maven plugin goal?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. In the list that opens, select Run Maven Goal. In the Select Maven Goal dialog, specify a project and a goal that you want to execute before launching the project. Click OK.

What is executions in Maven plugin?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.


1 Answers

Yes, <pluginManagement> is used to create ready-to-use configurations, but does not automatically activate your plugins - you still need to include them. So in effect you are right, <pluginManagement>, just like <dependencyManagement> are very useful in the parent pom to centralize plugin configurations and dependency management.

Effectively, 'declaring' your plugins in the right module benefits from a much more compact syntax:

<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>
like image 167
Patrice M. Avatar answered Sep 20 '22 14:09

Patrice M.