在 Maven 中执行的插件中包含依赖项时出错

error when including dependency within the plugin under execution in maven

我有以下 pom.xml 如果我直接执行 mvn 目标 mvn hibernate3:hbm2java 就可以工作。我现在想让它成为 generate-entity 阶段执行的一部分。我在插件中包含了一些依赖项。

这是工作 pom。

   <plugins>
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>hibernate3-maven-plugin</artifactId>
           <version>2.2</version>
             <configuration>
               <components>
                 <component>
                   <name>hbm2java</name>
                   <implementation>jdbcconfiguration</implementation>
                   <outputDirectory>src/main/java</outputDirectory>
                 </component>
               </components>
               <componentProperties>
                 <revengfile>src/main/resources/reveng.xml</revengfile>
                 <propertyfile>src/main/resources/hibernate.properties</propertyfile>
                 <packagename>com.whatever.domain</packagename>
                 <jdk7>true</jdk7>
                 <ejb3>true</ejb3>
               </componentProperties>
             </configuration>
             <dependencies>
               <dependency>
                 <groupId>cglib</groupId>
                 <artifactId>cglib-nodep</artifactId>
                 <version>2.2.2</version>
               </dependency>
               <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.22</version>
        </dependency>
             </dependencies>
           </plugin>
        </plugins>

这在我执行 mvn hibernate3:hbm2java 时按预期工作。

但我在 pom.xml 中包含了执行部分。现在 Eclipse 提示我这个错误消息

cvc-complex-type.2.4.a: Invalid content was found starting with element 'dependencies'. One of '{"http:// maven.apache.org/POM/4.0.0":inherited}' is expected.

这是修改后的 pom.xml,在插件 dependencies block 附近有问题

<plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>generate-entity</id>
                        <phase>generate-entity</phase>
                        <goals>
                            <goal>hbm2ddl</goal>
                        </goals>
                        <configuration>
                            <components>
                                <component>
                                    <name>hbm2hbmxml</name>
                                    <implementation>jdbcconfiguration</implementation>
                                    <outputDirectory>src/main/java</outputDirectory>
                                </component>
                                <component>
                                    <name>hbm2java</name>
                                    <implementation>jdbcconfiguration</implementation>
                                    <outputDirectory>src/main/java</outputDirectory>
                                </component>
                            </components>
                            <componentProperties>
                                <revengfile>src/main/resources/reveng.xml</revengfile>
                                <propertyfile>src/main/resources/hibernate.properties</propertyfile>
                                <packagename>com.whatever.domain</packagename>
                                <jdk7>true</jdk7>
                                <ejb3>true</ejb3>
                            </componentProperties>
                        </configuration>
                        <dependencies> --- Eclipse shows errors here
                            <dependency>
                                <groupId>cglib</groupId>
                                <artifactId>cglib-nodep</artifactId>
                                <version>2.2.2</version>
                            </dependency>
                            <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>5.1.22</version>
                            </dependency>
                        </dependencies>
                    </execution>
                </executions>
            </plugin>
        </plugins>

如“Guide to Configuring Plug-ins: Using the dependencies Tag”中所述,dependencies 标签仅在 plugin 级别可用,在 execution 级别不可用,如下例所示:-

<build>
    <plugins>
        <plugin>
            <groupId>some-group</groupId>
            <artifactId>some-artifact</artifactId>
            <version>some-version</version>
            ...
            <dependencies>
                <dependency>
                    <groupId>some-dependency-group</groupId>
                    <artifactId>some-dependency-artifact</artifactId>
                    <version>some-dependency-version</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>